Elina Mohanty Elina Mohanty - 1 year ago 84
Android Question

Getting current Location in Android API level 23

Hello i am completely new in android location concept, i have created one map activity in android studio. this is the code.

public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;


Location location = null;
LatLng currentPosition = new LatLng(location.getLatitude(), location.getLongitude());
mMap.addMarker(new MarkerOptions().position(currentPosition).title("Current Location"));

Is this is correct @Abhishek


You can use like this

public void onMapReady(GoogleMap map) {
    // TODO Auto-generated method stub
    LatLng currentPosition = new LatLng(location.getLatitude(),location.getLongitude());
    map.addMarker(new MarkerOptions().position(currentPosition).title("Current Location"));

location which get from onLocationChanged method

public void onLocationChanged(Location loc) {
// TODO Auto-generated method stub
 location = new LatLng(loc.getLatitude(), loc.getLongitude());