我有获取经纬度坐标的代码。
String bestProvider;
LocationManager lm = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProvider = lm.getBestProvider(criteria, true);
Location location = lm.getLastKnownLocation(bestProvider);
if (location == null){
}else{
geocoder = new Geocoder(this);
try {
setLat((double)location.getLatitude());
setLng((double)location.getLongitude());
}catch (Exception e) {
e.printStackTrace();
}
}
我尝试使用不同的设备。有些返回纬度和经度的值。有些没有。所有设备都连接到互联网并启用了 gps。你们知道是什么原因造成的吗?谢谢!
最佳答案
这是由于 getLastKnownLocation 可能存在也可能不存在。我建议您请求单个位置更新。还要记住,lastknownlocation 不一定准确,它可能属于 2 天前的位置。 开发指南: http://developer.android.com/reference/android/location/LocationManager.html
单次更新指南 http://androidexperinz.wordpress.com/2012/04/19/current-location-update/
关于android - 位置映射未在不同设备上返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18632762/