我正在开发一个应用程序,我需要计算距离当前位置和其他位置的距离。我使用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提供错误的格式。显然这应该用逗号分隔,而不是点...
这不是他要求的,请阅读问题 – Jay 2012-02-29 08:36:06