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?
Asked
Active
Viewed 4,252 times
1
-
looking at the documentation would probably be a good start :https://github.com/yandex/mapkit-android-demo , specifically https://github.com/yandex/mapkit-android-demo/blob/master/src/main/java/com/yandex/mapkitdemo/MapActivity.java – a_local_nobody Aug 14 '19 at 10:13
-
exactly what I did first as I mentioned in my question – Laura Aug 14 '19 at 10:26
-
yip I understand that, just saying you can use what's in there `mapView.getMap().move( new CameraPosition(TARGET_LOCATION, 14.0f, 0.0f, 0.0f), new Animation(Animation.Type.SMOOTH, 5), null);` to move to a location, then just get current location with android's `FusedLocation` – a_local_nobody Aug 14 '19 at 10:29
3 Answers
4
I have found one simple solution. The map kit 3.0.4 seems to have updated its api methods.
MapKit mapKit = MapKitFactory.getInstance();
mapKit.createLocationManager().requestSingleUpdate(new LocationListener() {
@Override
public void onLocationUpdated(@NonNull Location location) {
Log.d("TagCheck", "LocationUpdated " + location.getPosition().getLongitude());
Log.d("TagCheck", "LocationUpdated " + location.getPosition().getLatitude());
mapView.getMap().move(
new CameraPosition(location.getPosition(), 14.0f, 0.0f, 0.0f),
new Animation(Animation.Type.SMOOTH, 1),
null);
}
@Override
public void onLocationStatusUpdated(@NonNull LocationStatus locationStatus) {
}
});
this code will trigger device location.
dont forget to include MapKitFactory.setApiKey(MAPKIT_API_KEY);
and MapKitFactory.initialize(this);
before setContentview or returning view in fragments.

Azamat Mahkamov
- 912
- 14
- 18
0
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")
}
}

Jasurbek Oripov
- 1
- 1
-
3While this code may solve the question, [including an explanation](//meta.stackexchange.com/q/114762) of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please [edit] your answer to add explanations and give an indication of what limitations and assumptions apply. – Suraj Rao Oct 21 '21 at 05:35
-
Use the [edit] link below your post to add more info instead of adding in the comments – Suraj Rao Oct 21 '21 at 05:44
0
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) {
}
});

Arty Morris
- 99
- 2