AI-generated Key Takeaways
-
The LocationSource interface is used to provide location data, typically to a GoogleMap object.
-
A GoogleMap object's built-in location provider can be replaced with one that implements the LocationSource interface.
-
Implementations of LocationSource are activated and deactivated, and when active, they should provide periodic location updates to a registered listener while managing location services efficiently.
-
The LocationSource interface includes an abstract method
activateto start location updates and an abstract methoddeactivateto stop them.
Defines an interface for providing location data, typically to a GoogleMap
object.
A GoogleMap object
has a built-in location provider for its my-location layer, but it can be
replaced with another one that implements this interface.
A GoogleMap object
activates its location provider using
activate(OnLocationChangedListener). While active (between
activate(OnLocationChangedListener) and deactivate()),
a location provider should push periodic location updates to the listener registered in
activate(OnLocationChangedListener). It is the provider's responsibility to use
location services wisely according to the map's lifecycle state. For example, it should only
using battery-intensive services (like GPS) occasionally, or only while an activity is in the
foreground.
Nested Class Summary
| interface | LocationSource.OnLocationChangedListener | Handles a location update. | |
Public Method Summary
| abstract void | |
| abstract void |
deactivate()
Deactivates this provider.
|
Public Methods
public abstract void activate (LocationSource.OnLocationChangedListener listener)
Activates this provider. This provider will notify the supplied listener
periodically, until you call deactivate().
Notifications will be broadcast on the main thread.
Parameters
| listener | listener that's called when a new location is available |
|---|
Throws
| IllegalStateException | if this provider is already active |
|---|---|
| IllegalArgumentException | if listener is null |
public abstract void deactivate ()
Deactivates this provider. The previously-registered callback is not notified of any further updates.
Throws
| IllegalStateException | if this provider is already inactive |
|---|