1

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...

Kara
  • 6,115
  • 16
  • 50
  • 57
Alexander
  • 133
  • 2
  • 10

3 Answers3

0

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...

Alexander
  • 133
  • 2
  • 10
0

Have you used the permissions specified in this post? Else it kicks back to using cell tower triangulation. Other question

Community
  • 1
  • 1
Jay
  • 833
  • 7
  • 15
  • Hi Jay, thank you for fast response. The minute I posted the question I found the problem :P See solution above. – Alexander Feb 29 '12 at 08:41
-1

you can do something like as below. Create a location variable in that you have to assign location change var

@Override
public void onLocationChanged(Location arg0) {
    Location current = new Location("Current location");
    current=arg0;
    Log.v("Current LAT", "" + current.getLatitude());
}
Maneesh
  • 6,098
  • 5
  • 36
  • 55