Search code examples
androidgoogle-mapsgoogle-maps-mobile

Android Google Maps - getLastKnownLocation returns inaccurate latitude and longitude


I am developing an app where I need to calculate the distance from the current position and some other locations. I am using the GPS to access the users current location and the other locations coordinates are stored in a database. The problem occurs in the following snippet:

@Override
public void onLocationChanged(Location arg0) {
    Log.v("LOCATION LAT", String.valueOf(arg0.getLatitude()));
    currentLocation = arg0; //currentLocation is a global class variable
}

The problem is when I feed the DDMS with coordinates such as: Latitude: 62.639579 Longitude: 17.909689 and log these values I get Latitude: 62.0 and Longitude 17.0 .

If I create a location object and set the lat and lng values myself it works. Like this:

@Override
public void onLocationChanged(Location arg0) {
    Location current = new Location("Current location");
    current.setLatitude(62.639579);
    current.setLongitude(17.909689);
    Log.v("Current LAT", "" + current.getLatitude());
}

EDIT SOLVED:
Found the problem. I was feeding the the DDMS with faulty formatting. Apparently this should be delimited with a comma sign, not a dot...


Solution

  • Found the problem. I was feeding the the DDMS with faulty formatting. Apparently the coordinates should be delimited with a comma sign, not a dot...