react-native-google-maps-plus 1.10.0-dev.5 → 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.
|
@@ -34,10 +34,12 @@ class LocationHandler(
|
|
|
34
34
|
private var listener: LocationSource.OnLocationChangedListener? = null
|
|
35
35
|
private var locationRequest: LocationRequest? = null
|
|
36
36
|
private var locationCallback: LocationCallback? = null
|
|
37
|
+
private var lastLocation: Location? = null
|
|
38
|
+
private var isActive = false
|
|
39
|
+
|
|
37
40
|
private var priority: Int = PRIORITY_DEFAULT
|
|
38
41
|
private var interval: Long = INTERVAL_DEFAULT
|
|
39
42
|
private var minUpdateInterval: Long = MIN_UPDATE_INTERVAL
|
|
40
|
-
private var isActive = false
|
|
41
43
|
|
|
42
44
|
var onUpdate: ((Location) -> Unit)? = null
|
|
43
45
|
var onError: ((RNLocationErrorCode) -> Unit)? = null
|
|
@@ -128,6 +130,17 @@ class LocationHandler(
|
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
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
|
+
|
|
131
144
|
@SuppressLint("MissingPermission")
|
|
132
145
|
fun start() {
|
|
133
146
|
if (isActive) return
|
|
@@ -142,23 +155,22 @@ class LocationHandler(
|
|
|
142
155
|
return
|
|
143
156
|
}
|
|
144
157
|
try {
|
|
145
|
-
fusedLocationClientProviderClient
|
|
158
|
+
fusedLocationClientProviderClient
|
|
159
|
+
.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, null)
|
|
146
160
|
.addOnSuccessListener { location ->
|
|
147
|
-
if (location
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
161
|
+
if (location == null) return@addOnSuccessListener
|
|
162
|
+
if (!isNewerLocation(location)) return@addOnSuccessListener
|
|
163
|
+
notifyListener(location)
|
|
151
164
|
}.addOnFailureListener { e ->
|
|
152
|
-
|
|
153
|
-
onError?.invoke(error)
|
|
165
|
+
onError?.invoke(e.toLocationErrorCode(context))
|
|
154
166
|
}
|
|
155
167
|
locationCallback =
|
|
156
168
|
object : LocationCallback() {
|
|
157
169
|
override fun onLocationResult(locationResult: LocationResult) {
|
|
158
170
|
val location = locationResult.lastLocation
|
|
159
171
|
if (location != null) {
|
|
160
|
-
|
|
161
|
-
|
|
172
|
+
if (!isNewerLocation(location)) return
|
|
173
|
+
notifyListener(location)
|
|
162
174
|
} else {
|
|
163
175
|
onError?.invoke(RNLocationErrorCode.POSITION_UNAVAILABLE)
|
|
164
176
|
}
|
|
@@ -192,6 +204,9 @@ class LocationHandler(
|
|
|
192
204
|
|
|
193
205
|
override fun activate(listener: LocationSource.OnLocationChangedListener) {
|
|
194
206
|
this.listener = listener
|
|
207
|
+
lastLocation?.let {
|
|
208
|
+
listener.onLocationChanged(it)
|
|
209
|
+
}
|
|
195
210
|
}
|
|
196
211
|
|
|
197
212
|
override fun deactivate() {
|
package/package.json
CHANGED