react-native-google-maps-plus 1.10.0-dev.6 → 1.10.0-dev.7

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.
@@ -130,6 +130,17 @@ class LocationHandler(
130
130
  }
131
131
  }
132
132
 
133
+ private fun isNewerLocation(location: Location): Boolean {
134
+ val prev = lastLocation ?: return true
135
+ return location.elapsedRealtimeNanos > prev.elapsedRealtimeNanos
136
+ }
137
+
138
+ private fun notifyListener(location: Location) {
139
+ lastLocation = location
140
+ listener?.onLocationChanged(location)
141
+ onUpdate?.invoke(location)
142
+ }
143
+
133
144
  @SuppressLint("MissingPermission")
134
145
  fun start() {
135
146
  if (isActive) return
@@ -147,11 +158,9 @@ class LocationHandler(
147
158
  fusedLocationClientProviderClient
148
159
  .getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, null)
149
160
  .addOnSuccessListener { location ->
150
- if (location != null) {
151
- lastLocation = location
152
- listener?.onLocationChanged(location)
153
- onUpdate?.invoke(location)
154
- }
161
+ if (location == null) return@addOnSuccessListener
162
+ if (!isNewerLocation(location)) return@addOnSuccessListener
163
+ notifyListener(location)
155
164
  }.addOnFailureListener { e ->
156
165
  onError?.invoke(e.toLocationErrorCode(context))
157
166
  }
@@ -160,9 +169,8 @@ class LocationHandler(
160
169
  override fun onLocationResult(locationResult: LocationResult) {
161
170
  val location = locationResult.lastLocation
162
171
  if (location != null) {
163
- lastLocation = location
164
- listener?.onLocationChanged(location)
165
- onUpdate?.invoke(location)
172
+ if (!isNewerLocation(location)) return
173
+ notifyListener(location)
166
174
  } else {
167
175
  onError?.invoke(RNLocationErrorCode.POSITION_UNAVAILABLE)
168
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-google-maps-plus",
3
- "version": "1.10.0-dev.6",
3
+ "version": "1.10.0-dev.7",
4
4
  "description": "React Native wrapper for Android & iOS Google Maps SDK",
5
5
  "main": "./lib/module/index.js",
6
6
  "module": "./lib/module/index.js",