I am developing an Android application whereby a map is shown and the location of the device is tracked on a point on the map. I am using the Azure Maps SDK for the map itself and FusedLocationProviderClient (Play Services) for getting the GPS coordinates. The way I'm doing it now is that I'm writing my coordinates to variables with FusedLocationProviderClient and reading them again on map creation in Azure. The problem with that approach is that it will only show my location for the moment I create the app, but will not dynamically change it when I move around. What I want is a way to modify the map after creation. How is that done?
For some context, this is the code I'm using for retrieving the coordinates (Kotlin:)
var location = fusedLocationClient.lastLocation.result
var currentLong : Double = location?.longitude?:0.0
var currentLat : Double = location?.latitude?:0.0
locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
locationResult ?: return
for (location in locationResult.locations) {
currentLat = location.latitude
currentLong = location.longitude
// This is just so I make sure that the values actually change
latitudeView.text = currentLat.toString()
longitudeView.text = currentLong.toString()
task = client.checkLocationSettings(builder.build())
}
}
}
fusedLocationClient.requestLocationUpdates(
locationRequest,
locationCallback,
Looper.getMainLooper()
)
And this is the code for writing a dot on the map
mapControl.onReady {map : AzureMap ->
//Create a data source and add it to the map.
val dataSource =
DataSource()
map.sources.add(dataSource)
//Create a list of points.
dataSource.add(Feature.fromGeometry(Point.fromLngLat(currentLong, currentLat)))
//Create a LineString feature and add it to the data source.
//Create a line layer and add it to the map.
map.layers.add(SymbolLayer(dataSource))
}
I'm new to the field and the documentation is not helping, so all help is appreciated.