Xarialon Xarialon - 1 year ago 96
Android Question

How do I get my current location in Google Maps API V2

I'm creating an app where the user needs to see his/her geo location with getMyLocation(), but this is returning null. Is there any solution for this, because I did read that the getMyLocation() method is always returning null. I'm new to Google Maps, so any help will be appreciated!


GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
Location myLocation = map.getMyLocation();

if( myLocation != null ){
helper.showToast( "Latitude: " + myLocation.getLatitude() + "\nLongitude: " + myLocation.getLongitude() );


please check the sample code of the Google Maps Android API v2 , Using this you will solve your problem.

Sample Code