public class LocationSource
extends com.mapbox.services.android.telemetry.location.LocationEngine
implements com.mapzen.android.lost.api.LocationListener
Note: If registering a listener in your Activity.onStart() implementation, you should unregister it in Activity.onStop(). (You won't receive location updates when paused, and this will cut down on unnecessary system overhead). Do not unregister in Activity.onSaveInstanceState(), because this won't be called if the user moves back in the history stack.
Constructor and Description |
---|
LocationSource(Context context)
Constructs a location source instance.
|
Modifier and Type | Method and Description |
---|---|
void |
activate()
Activate the location engine which will connect whichever location provider you are using.
|
void |
deactivate()
Disconnect the location engine which is useful when you no longer need location updates or requesting the users
LocationEngine.getLastLocation() . |
Location |
getLastLocation()
Returns the Last known location is the location provider is connected and location permissions are granted.
|
boolean |
isConnected()
Check if your location provider has been activated/connected.
|
void |
onLocationChanged(Location location)
Invoked when the Location has changed.
|
void |
removeLocationUpdates()
Dismiss ongoing location update to the location provider.
|
void |
requestLocationUpdates()
Request location updates to the location provider.
|
addLocationEngineListener, getFastestInterval, getInterval, getPriority, getSmallestDisplacement, isBetterLocation, removeLocationEngineListener, setFastestInterval, setInterval, setPriority, setSmallestDisplacement
public LocationSource(Context context)
context
- the context from which the Application context will be derived.public void activate()
LocationEngine.requestLocationUpdates()
.activate
in class com.mapbox.services.android.telemetry.location.LocationEngine
public void deactivate()
LocationEngine.getLastLocation()
. Before deactivating, you'll need to stop request user location updates
using LocationEngine.removeLocationUpdates()
.deactivate
in class com.mapbox.services.android.telemetry.location.LocationEngine
public boolean isConnected()
isConnected
in class com.mapbox.services.android.telemetry.location.LocationEngine
@Nullable public Location getLastLocation()
getLastLocation
in class com.mapbox.services.android.telemetry.location.LocationEngine
public void requestLocationUpdates()
requestLocationUpdates
in class com.mapbox.services.android.telemetry.location.LocationEngine
public void removeLocationUpdates()
removeLocationUpdates
in class com.mapbox.services.android.telemetry.location.LocationEngine
public void onLocationChanged(Location location)
onLocationChanged
in interface com.mapzen.android.lost.api.LocationListener
location
- the new location© 2015–2017 Mapbox. All rights reserved.