You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Do some stuff when a new location has been found.
121
-
}
122
-
};
123
-
tracker.startListening();
124
-
```
125
-
126
-
In this case, when a location is found, the tracker will not call `onLocationFound()` again during *30 minutes*.
127
-
Moreover, if the distance between the new location and the older one is less than 100m, `onLocationFound()` will not be called.
63
+
```kotlin
64
+
locationTracker.addListener(object:Listener {
128
65
129
-
Be aware that the *time* parameter's priority is higher than the *distance* parameter. So even if the user has moved from 2km, the `tracker` will call `onLocationFound()` only after *30 minutes*.
66
+
funonLocationFound(location:Location) {
67
+
}
130
68
131
-
### Manage the tracker
69
+
funonProviderError(providerError:ProviderError) {
70
+
}
132
71
133
-
By default, after a `LocationTracker` is created, it automatically starts listening to updates... and never stops.
134
-
`LocationTracker` has two methods to *start* and *stop* listening for updates.
72
+
});
73
+
```
135
74
136
-
If you want to *stop* listening for updates, just call the `stopListening()` method.
137
-
For example, if you need a *one shot* position, you can do that:
// Do some stuff when a new GPS Location has been found
147
-
}
148
-
};
149
-
tracker.startListening();
78
+
```kotlin
79
+
locationTracker.startListening(context)
80
+
//and
81
+
locationTracker.stopListening()
150
82
```
151
83
152
-
You can also do it in the `onPause()` Activity method if you want.
84
+
### Provide custom use
153
85
154
-
```java
155
-
@Override
156
-
protectedvoid onPause() {
157
-
if(myTracker !=null) {
158
-
myTracker.stopListening();
159
-
}
160
-
super.onPause();
161
-
}
162
-
```
86
+
You can create a `LocationTracker` with custom parameters.
163
87
164
-
REMEMBER! A `LocationTracker` never stops untill you tell it to do so.
88
+
-`minTimeBetweenUpdates` minimum time between two locations to respect before notifying the listeners in milliseconds). Default is *5 minutes*
89
+
-`minDistanceBetweenUpdates` minimum distance between two locations to respect before notifying the listeners in meters). Default is *100 meters*
90
+
-`shouldUseGPS` specifies if the tracker should use the GPS locations or not. Default is *true*
91
+
-`shouldUseNetwork` specifies if the tracker should use the GPS locations or not. Default is *true*
92
+
-`shouldUsePassive` specifies if the tracker should use the passive locations or not. Default is *true*
165
93
166
-
You may want to start listening for updates after all. To do that, `LocationTracker` has a public method named `startListening()`, call it when you want.
94
+
With the default parameters, when a location is found, the tracker will not call `onLocationFound()` again during *5 minutes*.
95
+
Moreover, if the distance between the new location and the older one is less than *100m*, `onLocationFound()` will not be called.
167
96
168
-
For example, in the `onResume()` Activity method:
169
-
```java
170
-
@Override
171
-
protectedvoid onResume() {
172
-
if(myTracker !=null) {
173
-
myTracker.startListening();
174
-
}
175
-
super.onResume();
176
-
}
177
-
```
178
-
### Overriding
97
+
> Be aware that the priority of the **time** parameter is higher than the priority of the *distance* parameter.
98
+
> So even if the user has moved from 200km, the `tracker` will call `onLocationFound()` only after *30 minutes*.
> Be aware! A `LocationTracker` never stops running until you tell it to do so.
183
103
184
-
Excepts the `onLocationChanged()` method, you can override all the [LocationListener](http://developer.android.com/reference/android/location/LocationListener.html)'s metods, so here is the list:
185
-
<ul>
186
-
<li>onProviderDisabled(String provider)</li>
187
-
<li>onProviderEnabled(String provider)</li>
188
-
<li>onStatusChanged(String provider, int status, Bundle extras)</li>
189
-
</ul>
104
+
If the tracker is running in foreground and not in a service, it might be a good idea to link to the `lifecycle`
190
105
191
-
### Contact & Questions
106
+
The `stopListening` method has an optional parameter `cleanListeners` that is *false* by default.
107
+
(calling `stopListening(false)` is the same as calling `stopListening()`).
192
108
193
-
If you have any questions, fell free to send me a mail.
194
-
You can also fork this project, or open an issue :)
109
+
When calling `stopListening` we do not remove the listeners you've set, so they will be notified once you start listening again.
110
+
But calling `stopListening(true)` will clear the list of registered listeners (same as calling `removeListener` for every registered listener).
0 commit comments