2012-02-29 33 views
1

我正在开发一个应用程序,我需要计算距离当前位置和其他位置的距离。我使用GPS访问用户当前位置,其他位置坐标存储在数据库中。发生在下面的代码片段的问题:Android Google Maps - getLastKnownLocation返回的经纬度不准确

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

问题是,当我喂DDMS坐标如: 纬度:62.639579 经度:17.909689和记录这些值我得到纬度:62.0经度和17.0。

如果我创建一个位置对象并自己设置lat和lng值,它就可以工作。就像这样:

@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()); 
} 

编辑解决:
发现问题。我正在给DDMS提供错误的格式。显然这应该用逗号分隔,而不是点...

回答

0

发现问题。我正在给DDMS提供错误的格式。显然坐标应该用逗号分隔,而不是一个点...

-1

你可以做类似下面的事情。创建一个位置变量,您必须指定位置更改变量

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

这不是他要求的,请阅读问题 – Jay 2012-02-29 08:36:06

0

您是否使用了本文中指定的权限?否则它会踢回到使用手机塔三角测量。 Other question

+0

嗨周杰伦,谢谢你的快速回复。当我发布问题时,我发现问题:P请参阅上面的解决方案。 – Alexander 2012-02-29 08:41:41

+0

很高兴看到它的解决:) – Jay 2012-02-29 08:48:33

相关问题