Showing the User's Location
MapLayr includes a LocationMarker class which can be added to the MapView to display the user's location.
Add the positioning-google Dependency
The LocationMarker class takes a LocationProvider parameter, which is provided by the positioning-google library. In your module build.gradle file add the following dependency:
An example can be found here: app/build.gradle
Add a Location Marker
Then construct a LocationMarker instance using either GoogleLocationId.HighAccuracy, GoogleLocationId.Balanced or GoogleLocationId.Passive and add it to the map view. The position of the location marker will then automatically update with the user's location provided by Google location services.
val locationMarker = LocationMarker(GoogleLocationId.HighAccuracy)
mapView.addLocationMarker(locationMarker)
Location Permission
The MapLayr SDK does not handle location permissions so these must be implemented by the consuming application.
An example can be found here: ExtendedSampleActivity.kt
Observing Location Updates
To observe location updates retrieve a LiveData<LocationResponse> for your desired LocationId from the GlobalLocationManager.
GlobalLocationManager.getLocationLiveData(GoogleLocationId.HighAccuracy).observe(lifecycleOwner = lifecycleOwner) { locationResponse ->
when (locationResponse) {
is Location -> println("Location: ${locationResponse.geographicCoordinate}")
LocationResponse.NotPermitted -> println("Location: Permissions not granted.")
LocationResponse.Pending -> println("Location: Pending...")
}
}
An example can be found here: NonMapViewSampleActivity.kt
