Android, Java

Retrieve longitude and latitude in Android

You can get your last geo location in Android with this code:

1
2
3
4
5
6
7
8
LocationManager lm = (LocationManager)activity.getSystemService(Context.LOCATION_SERVICE); 
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double longitude = 0;
double latitude  = 0;
if(location!=null){
    longitude = location.getLongitude();
    latitude = location.getLatitude();
}

Don’t forget to enable permission ACCESS_FINE_LOCATION in manifest!