react-native-google-maps-plus 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/android/src/main/java/com/rngooglemapsplus/GoogleMapsViewImpl.kt +41 -144
  2. package/android/src/main/java/com/rngooglemapsplus/LocationHandler.kt +38 -36
  3. package/android/src/main/java/com/rngooglemapsplus/extensions/CameraPositionExtension.kt +12 -0
  4. package/android/src/main/java/com/rngooglemapsplus/extensions/IntExtension.kt +28 -0
  5. package/android/src/main/java/com/rngooglemapsplus/extensions/LatLngBounds.kt +15 -0
  6. package/android/src/main/java/com/rngooglemapsplus/extensions/LocationExtension.kt +59 -0
  7. package/ios/GoogleMapViewImpl.swift +28 -138
  8. package/ios/LocationHandler.swift +5 -13
  9. package/ios/MapHelper.swift +20 -0
  10. package/ios/MapMarkerBuilder.swift +44 -69
  11. package/ios/RNGoogleMapsPlusView.swift +12 -8
  12. package/ios/extensions/CLError+Extension.swift +14 -0
  13. package/ios/extensions/CLLocation+Extension.swift +27 -0
  14. package/ios/extensions/GMSCameraPosition+Extension.swift +12 -0
  15. package/ios/extensions/GMSCoordinateBounds+Extension.swift +19 -0
  16. package/ios/extensions/RNMarker+Extension.swift +2 -3
  17. package/lib/module/GoogleMapsPlus.js +7 -0
  18. package/lib/module/GoogleMapsPlus.js.map +1 -0
  19. package/lib/module/index.js +3 -5
  20. package/lib/module/index.js.map +1 -1
  21. package/lib/module/types.js.map +1 -1
  22. package/lib/nitrogen/generated/shared/json/RNGoogleMapsPlusViewConfig.json +44 -0
  23. package/lib/typescript/src/GoogleMapsPlus.d.ts +5 -0
  24. package/lib/typescript/src/GoogleMapsPlus.d.ts.map +1 -0
  25. package/lib/typescript/src/index.d.ts +3 -3
  26. package/lib/typescript/src/index.d.ts.map +1 -1
  27. package/lib/typescript/src/types.d.ts +25 -0
  28. package/lib/typescript/src/types.d.ts.map +1 -1
  29. package/nitrogen/generated/android/c++/JFunc_void_RNLocation.hpp +6 -0
  30. package/nitrogen/generated/android/c++/JHybridRNGoogleMapsPlusViewSpec.cpp +8 -0
  31. package/nitrogen/generated/android/c++/JRNLocation.hpp +32 -2
  32. package/nitrogen/generated/android/c++/JRNLocationAndroid.hpp +82 -0
  33. package/nitrogen/generated/android/c++/JRNLocationIOS.hpp +77 -0
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNLocation.kt +19 -1
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNLocationAndroid.kt +50 -0
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/RNLocationIOS.kt +47 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/rngooglemapsplus/views/HybridRNGoogleMapsPlusViewManager.kt +7 -2
  38. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Bridge.hpp +36 -0
  39. package/nitrogen/generated/ios/RNGoogleMapsPlus-Swift-Cxx-Umbrella.hpp +6 -0
  40. package/nitrogen/generated/ios/c++/HybridRNGoogleMapsPlusViewSpecSwift.hpp +6 -0
  41. package/nitrogen/generated/ios/c++/views/HybridRNGoogleMapsPlusViewComponent.mm +8 -0
  42. package/nitrogen/generated/ios/swift/RNLocation.swift +92 -2
  43. package/nitrogen/generated/ios/swift/RNLocationAndroid.swift +215 -0
  44. package/nitrogen/generated/ios/swift/RNLocationIOS.swift +185 -0
  45. package/nitrogen/generated/shared/c++/RNLocation.hpp +33 -2
  46. package/nitrogen/generated/shared/c++/RNLocationAndroid.hpp +104 -0
  47. package/nitrogen/generated/shared/c++/RNLocationIOS.hpp +99 -0
  48. package/package.json +6 -13
  49. package/src/GoogleMapsPlus.tsx +20 -0
  50. package/src/index.tsx +6 -14
  51. package/src/types.ts +27 -0
  52. package/lib/module/package.json +0 -1
  53. package/lib/typescript/package.json +0 -1
@@ -2,7 +2,6 @@ package com.rngooglemapsplus
2
2
 
3
3
  import android.annotation.SuppressLint
4
4
  import android.graphics.Bitmap
5
- import android.location.Location
6
5
  import android.util.Base64
7
6
  import android.util.Size
8
7
  import android.widget.FrameLayout
@@ -11,7 +10,6 @@ import com.facebook.react.bridge.LifecycleEventListener
11
10
  import com.facebook.react.bridge.UiThreadUtil
12
11
  import com.facebook.react.uimanager.PixelUtil.dpToPx
13
12
  import com.facebook.react.uimanager.ThemedReactContext
14
- import com.google.android.gms.common.ConnectionResult
15
13
  import com.google.android.gms.maps.CameraUpdateFactory
16
14
  import com.google.android.gms.maps.GoogleMap
17
15
  import com.google.android.gms.maps.GoogleMapOptions
@@ -39,7 +37,11 @@ import com.rngooglemapsplus.extensions.toLatLng
39
37
  import com.rngooglemapsplus.extensions.toLocationErrorCode
40
38
  import com.rngooglemapsplus.extensions.toRNIndoorBuilding
41
39
  import com.rngooglemapsplus.extensions.toRNIndoorLevel
40
+ import com.rngooglemapsplus.extensions.toRNMapErrorCodeOrNull
41
+ import com.rngooglemapsplus.extensions.toRnCamera
42
42
  import com.rngooglemapsplus.extensions.toRnLatLng
43
+ import com.rngooglemapsplus.extensions.toRnLocation
44
+ import com.rngooglemapsplus.extensions.toRnRegion
43
45
  import java.io.ByteArrayInputStream
44
46
  import java.io.ByteArrayOutputStream
45
47
  import java.io.File
@@ -65,6 +67,7 @@ class GoogleMapsViewImpl(
65
67
  LifecycleEventListener {
66
68
  private var initialized = false
67
69
  private var mapReady = false
70
+ private var destroyed = false
68
71
  private var googleMap: GoogleMap? = null
69
72
  private var mapView: MapView? = null
70
73
 
@@ -83,7 +86,6 @@ class GoogleMapsViewImpl(
83
86
  private val kmlLayersById = mutableMapOf<String, KmlLayer>()
84
87
 
85
88
  private var cameraMoveReason = -1
86
- private var lastSubmittedLocation: Location? = null
87
89
  private var lastSubmittedCameraPosition: CameraPosition? = null
88
90
 
89
91
  init {
@@ -94,31 +96,16 @@ class GoogleMapsViewImpl(
94
96
  if (initialized) return
95
97
  initialized = true
96
98
  val result = playServiceHandler.playServicesAvailability()
99
+ val errorCode = result.toRNMapErrorCodeOrNull()
97
100
 
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)
103
103
 
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
+ ) {
106
107
  return
107
108
  }
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)
122
109
  }
123
110
 
124
111
  mapView =
@@ -143,8 +130,8 @@ class GoogleMapsViewImpl(
143
130
  googleMap?.setOnMapClickListener(this@GoogleMapsViewImpl)
144
131
  googleMap?.setOnMarkerDragListener(this@GoogleMapsViewImpl)
145
132
  }
133
+ applyProps()
146
134
  initLocationCallbacks()
147
- applyPending()
148
135
  mapReady = true
149
136
  onMapReady?.invoke(true)
150
137
  }
@@ -160,21 +147,9 @@ class GoogleMapsViewImpl(
160
147
  }
161
148
  val isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == reason
162
149
 
163
- val latDelta = bounds.northeast.latitude - bounds.southwest.latitude
164
- val lngDelta = bounds.northeast.longitude - bounds.southwest.longitude
165
-
166
150
  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(),
178
153
  isGesture,
179
154
  )
180
155
  }
@@ -192,21 +167,9 @@ class GoogleMapsViewImpl(
192
167
 
193
168
  val isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
194
169
 
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(),
210
173
  isGesture,
211
174
  )
212
175
  }
@@ -220,39 +183,16 @@ class GoogleMapsViewImpl(
220
183
  }
221
184
  val isGesture = GoogleMap.OnCameraMoveStartedListener.REASON_GESTURE == cameraMoveReason
222
185
 
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(),
238
189
  isGesture,
239
190
  )
240
191
  }
241
192
 
242
193
  fun initLocationCallbacks() {
243
194
  locationHandler.onUpdate = { location ->
244
- // / only the coordinated are relevant right now
245
- if (lastSubmittedLocation?.latitude != location.latitude || lastSubmittedLocation?.longitude != location.longitude ||
246
- lastSubmittedLocation?.bearing != location.bearing
247
- ) {
248
- onLocationUpdate?.invoke(
249
- RNLocation(
250
- RNLatLng(location.latitude, location.longitude),
251
- location.bearing.toDouble(),
252
- ),
253
- )
254
- }
255
- lastSubmittedLocation = location
195
+ onLocationUpdate?.invoke(location.toRnLocation())
256
196
  }
257
197
 
258
198
  locationHandler.onError = { error ->
@@ -261,65 +201,18 @@ class GoogleMapsViewImpl(
261
201
  locationHandler.start()
262
202
  }
263
203
 
264
- fun applyPending() {
265
- onUi {
266
- mapPadding?.let {
267
- googleMap?.setPadding(
268
- it.left.dpToPx().toInt(),
269
- it.top.dpToPx().toInt(),
270
- it.right.dpToPx().toInt(),
271
- it.bottom.dpToPx().toInt(),
272
- )
273
- }
274
-
275
- uiSettings?.let { v ->
276
- googleMap?.uiSettings?.apply {
277
- v.allGesturesEnabled?.let { setAllGesturesEnabled(it) }
278
- v.compassEnabled?.let { isCompassEnabled = it }
279
- v.indoorLevelPickerEnabled?.let { isIndoorLevelPickerEnabled = it }
280
- v.mapToolbarEnabled?.let { isMapToolbarEnabled = it }
281
- v.myLocationButtonEnabled?.let {
282
- googleMap?.setLocationSource(locationHandler)
283
- isMyLocationButtonEnabled = it
284
- }
285
- v.rotateEnabled?.let { isRotateGesturesEnabled = it }
286
- v.scrollEnabled?.let { isScrollGesturesEnabled = it }
287
- v.scrollDuringRotateOrZoomEnabled?.let {
288
- isScrollGesturesEnabledDuringRotateOrZoom = it
289
- }
290
- v.tiltEnabled?.let { isTiltGesturesEnabled = it }
291
- v.zoomControlsEnabled?.let { isZoomControlsEnabled = it }
292
- v.zoomGesturesEnabled?.let { isZoomGesturesEnabled = it }
293
- }
294
- }
295
-
296
- buildingEnabled?.let {
297
- googleMap?.isBuildingsEnabled = it
298
- }
299
- trafficEnabled?.let {
300
- googleMap?.isTrafficEnabled = it
301
- }
302
- indoorEnabled?.let {
303
- googleMap?.isIndoorEnabled = it
304
- }
305
- googleMap?.setMapStyle(customMapStyle)
306
- mapType?.let {
307
- googleMap?.mapType = it
308
- }
309
- userInterfaceStyle?.let {
310
- googleMap?.mapColorScheme = it
311
- }
312
- mapZoomConfig?.let {
313
- googleMap?.setMinZoomPreference(it.min?.toFloat() ?: 2.0f)
314
- googleMap?.setMaxZoomPreference(it.max?.toFloat() ?: 21.0f)
315
- }
316
- }
317
-
318
- locationConfig?.let {
319
- locationHandler.priority = it.android?.priority?.toGooglePriority()
320
- locationHandler.interval = it.android?.interval?.toLong()
321
- locationHandler.minUpdateInterval = it.android?.minUpdateInterval?.toLong()
322
- }
204
+ fun applyProps() {
205
+ mapPadding = mapPadding
206
+ uiSettings = uiSettings
207
+ myLocationEnabled = myLocationEnabled
208
+ buildingEnabled = buildingEnabled
209
+ trafficEnabled = trafficEnabled
210
+ indoorEnabled = indoorEnabled
211
+ customMapStyle = customMapStyle
212
+ mapType = mapType
213
+ userInterfaceStyle = userInterfaceStyle
214
+ mapZoomConfig = mapZoomConfig
215
+ locationConfig = locationConfig
323
216
 
324
217
  if (pendingMarkers.isNotEmpty()) {
325
218
  pendingMarkers.forEach { (id, opts) ->
@@ -480,9 +373,11 @@ class GoogleMapsViewImpl(
480
373
  var locationConfig: RNLocationConfig? = null
481
374
  set(value) {
482
375
  field = value
483
- locationHandler.priority = value?.android?.priority?.toGooglePriority()
484
- locationHandler.interval = value?.android?.interval?.toLong()
485
- locationHandler.minUpdateInterval = value?.android?.minUpdateInterval?.toLong()
376
+ locationHandler.updateConfig(
377
+ value?.android?.priority?.toGooglePriority(),
378
+ value?.android?.interval?.toLong(),
379
+ value?.android?.minUpdateInterval?.toLong(),
380
+ )
486
381
  }
487
382
 
488
383
  var onMapError: ((RNMapErrorCode) -> Unit)? = null
@@ -919,7 +814,7 @@ class GoogleMapsViewImpl(
919
814
  onUi {
920
815
  heatmapsById.values.forEach { it.remove() }
921
816
  }
922
- circlesById.clear()
817
+ heatmapsById.clear()
923
818
  pendingHeatmaps.clear()
924
819
  }
925
820
 
@@ -968,6 +863,8 @@ class GoogleMapsViewImpl(
968
863
  }
969
864
 
970
865
  fun destroyInternal() {
866
+ if (destroyed) return
867
+ destroyed = true
971
868
  onUi {
972
869
  locationHandler.stop()
973
870
  markerBuilder.cancelAllJobs()
@@ -35,30 +35,28 @@ class LocationHandler(
35
35
  private var listener: LocationSource.OnLocationChangedListener? = null
36
36
  private var locationRequest: LocationRequest? = null
37
37
  private var locationCallback: LocationCallback? = null
38
-
39
- var priority: Int? = PRIORITY_DEFAULT
40
- set(value) {
41
- field = value ?: PRIORITY_DEFAULT
42
- start()
43
- }
44
-
45
- var interval: Long? = INTERVAL_DEFAULT
46
- set(value) {
47
- field = value ?: INTERVAL_DEFAULT
48
- buildLocationRequest()
49
- }
50
-
51
- var minUpdateInterval: Long? = MIN_UPDATE_INTERVAL
52
- set(value) {
53
- field = value ?: MIN_UPDATE_INTERVAL
54
- buildLocationRequest()
55
- }
38
+ private var priority: Int = PRIORITY_DEFAULT
39
+ private var interval: Long = INTERVAL_DEFAULT
40
+ private var minUpdateInterval: Long = MIN_UPDATE_INTERVAL
41
+ private var lastSubmittedLocation: Location? = null
42
+ private var isActive = false
56
43
 
57
44
  var onUpdate: ((Location) -> Unit)? = null
58
45
  var onError: ((RNLocationErrorCode) -> Unit)? = null
59
46
 
60
47
  init {
61
- buildLocationRequest()
48
+ buildLocationRequest(priority, interval, minUpdateInterval)
49
+ }
50
+
51
+ fun updateConfig(
52
+ priority: Int? = null,
53
+ interval: Long? = null,
54
+ minUpdateInterval: Long? = null,
55
+ ) {
56
+ this.priority = priority ?: PRIORITY_DEFAULT
57
+ this.interval = interval ?: INTERVAL_DEFAULT
58
+ this.minUpdateInterval = minUpdateInterval ?: MIN_UPDATE_INTERVAL
59
+ buildLocationRequest(this.priority, this.interval, this.minUpdateInterval)
62
60
  }
63
61
 
64
62
  fun showLocationDialog() {
@@ -108,11 +106,11 @@ class LocationHandler(
108
106
  }
109
107
 
110
108
  @Suppress("deprecation")
111
- private fun buildLocationRequest() {
112
- val priority = priority ?: Priority.PRIORITY_BALANCED_POWER_ACCURACY
113
- val interval = interval ?: INTERVAL_DEFAULT
114
- val minUpdateInterval = minUpdateInterval ?: MIN_UPDATE_INTERVAL
115
-
109
+ private fun buildLocationRequest(
110
+ priority: Int,
111
+ interval: Long,
112
+ minUpdateInterval: Long,
113
+ ) {
116
114
  locationRequest =
117
115
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
118
116
  LocationRequest
@@ -126,11 +124,13 @@ class LocationHandler(
126
124
  .setInterval(interval)
127
125
  .setFastestInterval(minUpdateInterval)
128
126
  }
129
- restartLocationUpdates()
130
127
  }
131
128
 
132
- private fun restartLocationUpdates() {
133
- stop()
129
+ @SuppressLint("MissingPermission")
130
+ fun start() {
131
+ if (isActive) return
132
+ isActive = true
133
+
134
134
  val playServicesStatus =
135
135
  GoogleApiAvailability
136
136
  .getInstance()
@@ -139,17 +139,13 @@ class LocationHandler(
139
139
  onError?.invoke(RNLocationErrorCode.PLAY_SERVICE_NOT_AVAILABLE)
140
140
  return
141
141
  }
142
- start()
143
- }
144
-
145
- @SuppressLint("MissingPermission")
146
- fun start() {
147
142
  try {
148
143
  fusedLocationClientProviderClient.lastLocation
149
144
  .addOnSuccessListener(
150
145
  OnSuccessListener { location ->
151
- if (location != null) {
146
+ if (location != null && location != lastSubmittedLocation) {
152
147
  onUpdate?.invoke(location)
148
+ lastSubmittedLocation = location
153
149
  }
154
150
  },
155
151
  ).addOnFailureListener { e ->
@@ -161,8 +157,11 @@ class LocationHandler(
161
157
  override fun onLocationResult(locationResult: LocationResult) {
162
158
  val location = locationResult.lastLocation
163
159
  if (location != null) {
164
- listener?.onLocationChanged(location)
165
- onUpdate?.invoke(location)
160
+ if (location != lastSubmittedLocation) {
161
+ lastSubmittedLocation = location
162
+ listener?.onLocationChanged(location)
163
+ onUpdate?.invoke(location)
164
+ }
166
165
  } else {
167
166
  onError?.invoke(RNLocationErrorCode.POSITION_UNAVAILABLE)
168
167
  }
@@ -186,9 +185,11 @@ class LocationHandler(
186
185
  }
187
186
 
188
187
  fun stop() {
189
- listener = null
188
+ if (!isActive) return
189
+ isActive = false
190
190
  if (locationCallback != null) {
191
191
  fusedLocationClientProviderClient.removeLocationUpdates(locationCallback!!)
192
+ fusedLocationClientProviderClient.flushLocations()
192
193
  locationCallback = null
193
194
  }
194
195
  }
@@ -199,6 +200,7 @@ class LocationHandler(
199
200
  }
200
201
 
201
202
  override fun deactivate() {
203
+ listener = null
202
204
  stop()
203
205
  }
204
206
  }
@@ -0,0 +1,12 @@
1
+ package com.rngooglemapsplus.extensions
2
+
3
+ import com.google.android.gms.maps.model.CameraPosition
4
+ import com.rngooglemapsplus.RNCamera
5
+
6
+ fun CameraPosition.toRnCamera(): RNCamera =
7
+ RNCamera(
8
+ center = target.toRnLatLng(),
9
+ zoom = zoom.toDouble(),
10
+ bearing = bearing.toDouble(),
11
+ tilt = tilt.toDouble(),
12
+ )
@@ -0,0 +1,28 @@
1
+ package com.rngooglemapsplus.extensions
2
+
3
+ import com.google.android.gms.common.ConnectionResult
4
+ import com.rngooglemapsplus.RNMapErrorCode
5
+
6
+ fun Int.toRNMapErrorCodeOrNull(): RNMapErrorCode? =
7
+ when (this) {
8
+ ConnectionResult.SERVICE_MISSING ->
9
+ RNMapErrorCode.PLAY_SERVICES_MISSING
10
+
11
+ ConnectionResult.SERVICE_INVALID ->
12
+ RNMapErrorCode.PLAY_SERVICES_INVALID
13
+
14
+ ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ->
15
+ RNMapErrorCode.PLAY_SERVICES_OUTDATED
16
+
17
+ ConnectionResult.SERVICE_UPDATING ->
18
+ RNMapErrorCode.PLAY_SERVICE_UPDATING
19
+
20
+ ConnectionResult.SERVICE_DISABLED ->
21
+ RNMapErrorCode.PLAY_SERVICES_DISABLED
22
+
23
+ ConnectionResult.SUCCESS ->
24
+ null
25
+
26
+ else ->
27
+ RNMapErrorCode.UNKNOWN
28
+ }
@@ -0,0 +1,15 @@
1
+ package com.rngooglemapsplus.extensions
2
+
3
+ import com.google.android.gms.maps.model.LatLngBounds
4
+ import com.rngooglemapsplus.RNRegion
5
+
6
+ fun LatLngBounds.toRnRegion(): RNRegion {
7
+ val latDelta = northeast.latitude - southwest.latitude
8
+ val lngDelta = northeast.longitude - southwest.longitude
9
+
10
+ return RNRegion(
11
+ center = center.toRnLatLng(),
12
+ latitudeDelta = latDelta,
13
+ longitudeDelta = lngDelta,
14
+ )
15
+ }
@@ -0,0 +1,59 @@
1
+ package com.rngooglemapsplus.extensions
2
+
3
+ import android.location.Location
4
+ import android.os.Build
5
+ import com.rngooglemapsplus.RNLatLng
6
+ import com.rngooglemapsplus.RNLocation
7
+ import com.rngooglemapsplus.RNLocationAndroid
8
+
9
+ fun Location.toRnLocation(): RNLocation =
10
+ RNLocation(
11
+ center = RNLatLng(latitude, longitude),
12
+ altitude = altitude,
13
+ accuracy = accuracy.toDouble(),
14
+ bearing = bearing.toDouble(),
15
+ speed = speed.toDouble(),
16
+ time = time.toDouble(),
17
+ android =
18
+ RNLocationAndroid(
19
+ provider = provider,
20
+ elapsedRealtimeNanos = elapsedRealtimeNanos.toDouble(),
21
+ bearingAccuracyDegrees =
22
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
23
+ bearingAccuracyDegrees.toDouble()
24
+ } else {
25
+ null
26
+ },
27
+ speedAccuracyMetersPerSecond =
28
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
29
+ speedAccuracyMetersPerSecond.toDouble()
30
+ } else {
31
+ null
32
+ },
33
+ verticalAccuracyMeters =
34
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
35
+ verticalAccuracyMeters.toDouble()
36
+ } else {
37
+ null
38
+ },
39
+ mslAltitudeMeters =
40
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
41
+ mslAltitudeMeters
42
+ } else {
43
+ null
44
+ },
45
+ mslAltitudeAccuracyMeters =
46
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
47
+ mslAltitudeAccuracyMeters.toDouble()
48
+ } else {
49
+ null
50
+ },
51
+ isMock =
52
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
53
+ isMock
54
+ } else {
55
+ isFromMockProvider
56
+ },
57
+ ),
58
+ ios = null,
59
+ )