I'm using Yandex MapKit in my application. Currently I need to get users current location and animate camera on that location. The problem is the documentation is really poor and most of the answers on the internet seem to be deprecated on latest version of map. How can I get the current location and location updates?
How to get user's current location and location updates on Yandex MapKit 3.4.0
5.1k Views Asked by Laura At
3
There are 3 best solutions below
2
On
First you need to get permisson for Location !!!
var fusedLocationClient =LocationServices.getFusedLocationProviderClient(this@MapActivity)
fusedLocationClient.lastLocation.addOnSuccessListener { location: Location? ->
Log.d(TAG, "getUserLocation: $location.latitude")
Log.d(TAG, "getUserLocation: $location.longitude")
}
}
0
On
The answer provided above is incorrect, it allows you to find out the location only once. You need to use a different code
mapKit = MapKitFactory.getInstance();
mapKit.createLocationManager().subscribeForLocationUpdates(0,0, 0, true, FilteringMode.ON, new LocationListener() {
@Override
public void onLocationUpdated(@NonNull Location location) {
Log.d("TagCheck", "LocationUpdated " + location.getPosition().getLongitude());
Log.d("TagCheck", "LocationUpdated " + location.getPosition().getLatitude());
}
@Override
public void onLocationStatusUpdated(@NonNull LocationStatus locationStatus) {
}
});
I have found one simple solution. The map kit 3.0.4 seems to have updated its api methods.
this code will trigger device location.
dont forget to include
MapKitFactory.setApiKey(MAPKIT_API_KEY);andMapKitFactory.initialize(this);before setContentview or returning view in fragments.