@@ -10,7 +10,6 @@ import com.facebook.react.bridge.LifecycleEventListener
1010import com.facebook.react.bridge.UiThreadUtil
1111import com.facebook.react.uimanager.PixelUtil.dpToPx
1212import com.facebook.react.uimanager.ThemedReactContext
13- import com.google.android.gms.common.ConnectionResult
1413import com.google.android.gms.maps.CameraUpdateFactory
1514import com.google.android.gms.maps.GoogleMap
1615import com.google.android.gms.maps.GoogleMapOptions
@@ -38,8 +37,11 @@ import com.rngooglemapsplus.extensions.toLatLng
3837import com.rngooglemapsplus.extensions.toLocationErrorCode
3938import com.rngooglemapsplus.extensions.toRNIndoorBuilding
4039import com.rngooglemapsplus.extensions.toRNIndoorLevel
40+ import com.rngooglemapsplus.extensions.toRNMapErrorCodeOrNull
41+ import com.rngooglemapsplus.extensions.toRnCamera
4142import com.rngooglemapsplus.extensions.toRnLatLng
4243import com.rngooglemapsplus.extensions.toRnLocation
44+ import com.rngooglemapsplus.extensions.toRnRegion
4345import java.io.ByteArrayInputStream
4446import java.io.ByteArrayOutputStream
4547import java.io.File
@@ -94,31 +96,16 @@ class GoogleMapsViewImpl(
9496 if (initialized) return
9597 initialized = true
9698 val result = playServiceHandler.playServicesAvailability()
99+ val errorCode = result.toRNMapErrorCodeOrNull()
97100
98- when (result) {
99- ConnectionResult .SERVICE_MISSING -> {
100- onMapError?.invoke(RNMapErrorCode .PLAY_SERVICES_MISSING )
101- return
102- }
101+ if (errorCode != null ) {
102+ onMapError?.invoke(errorCode)
103103
104- ConnectionResult .SERVICE_INVALID -> {
105- onMapError?.invoke(RNMapErrorCode .PLAY_SERVICES_INVALID )
104+ if (errorCode == RNMapErrorCode .PLAY_SERVICES_MISSING ||
105+ errorCode == RNMapErrorCode .PLAY_SERVICES_INVALID
106+ ) {
106107 return
107108 }
108-
109- ConnectionResult .SERVICE_VERSION_UPDATE_REQUIRED ->
110- onMapError?.invoke(RNMapErrorCode .PLAY_SERVICES_OUTDATED )
111-
112- ConnectionResult .SERVICE_UPDATING ->
113- onMapError?.invoke(RNMapErrorCode .PLAY_SERVICE_UPDATING )
114-
115- ConnectionResult .SERVICE_DISABLED ->
116- onMapError?.invoke(RNMapErrorCode .PLAY_SERVICES_DISABLED )
117-
118- ConnectionResult .SUCCESS -> {}
119-
120- else ->
121- onMapError?.invoke(RNMapErrorCode .UNKNOWN )
122109 }
123110
124111 mapView =
@@ -160,21 +147,9 @@ class GoogleMapsViewImpl(
160147 }
161148 val isGesture = GoogleMap .OnCameraMoveStartedListener .REASON_GESTURE == reason
162149
163- val latDelta = bounds.northeast.latitude - bounds.southwest.latitude
164- val lngDelta = bounds.northeast.longitude - bounds.southwest.longitude
165-
166150 onCameraChangeStart?.invoke(
167- RNRegion (
168- center = bounds.center.toRnLatLng(),
169- latitudeDelta = latDelta,
170- longitudeDelta = lngDelta,
171- ),
172- RNCamera (
173- center = cameraPosition.target.toRnLatLng(),
174- zoom = cameraPosition.zoom.toDouble(),
175- bearing = cameraPosition.bearing.toDouble(),
176- tilt = cameraPosition.tilt.toDouble(),
177- ),
151+ bounds.toRnRegion(),
152+ cameraPosition.toRnCamera(),
178153 isGesture,
179154 )
180155 }
@@ -192,21 +167,9 @@ class GoogleMapsViewImpl(
192167
193168 val isGesture = GoogleMap .OnCameraMoveStartedListener .REASON_GESTURE == cameraMoveReason
194169
195- val latDelta = bounds.northeast.latitude - bounds.southwest.latitude
196- val lngDelta = bounds.northeast.longitude - bounds.southwest.longitude
197-
198- onCameraChange?.invoke(
199- RNRegion (
200- center = bounds.center.toRnLatLng(),
201- latitudeDelta = latDelta,
202- longitudeDelta = lngDelta,
203- ),
204- RNCamera (
205- center = cameraPosition.target.toRnLatLng(),
206- zoom = cameraPosition.zoom.toDouble(),
207- bearing = cameraPosition.bearing.toDouble(),
208- tilt = cameraPosition.tilt.toDouble(),
209- ),
170+ onCameraChangeStart?.invoke(
171+ bounds.toRnRegion(),
172+ cameraPosition.toRnCamera(),
210173 isGesture,
211174 )
212175 }
@@ -220,21 +183,9 @@ class GoogleMapsViewImpl(
220183 }
221184 val isGesture = GoogleMap .OnCameraMoveStartedListener .REASON_GESTURE == cameraMoveReason
222185
223- val latDelta = bounds.northeast.latitude - bounds.southwest.latitude
224- val lngDelta = bounds.northeast.longitude - bounds.southwest.longitude
225-
226- onCameraChangeComplete?.invoke(
227- RNRegion (
228- center = bounds.center.toRnLatLng(),
229- latitudeDelta = latDelta,
230- longitudeDelta = lngDelta,
231- ),
232- RNCamera (
233- center = cameraPosition.target.toRnLatLng(),
234- zoom = cameraPosition.zoom.toDouble(),
235- bearing = cameraPosition.bearing.toDouble(),
236- tilt = cameraPosition.tilt.toDouble(),
237- ),
186+ onCameraChangeStart?.invoke(
187+ bounds.toRnRegion(),
188+ cameraPosition.toRnCamera(),
238189 isGesture,
239190 )
240191 }
0 commit comments