我试图让我的LatLong从Android设备与GPS。纬度不准确,但龙是准确的 - Android设备
有我的代码:
LocationManager lm,locationManager;
Location l;
TextView lt, ln;
lm=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
l=lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
updateWithNewLocation(l);
private void updateWithNewLocation(Location location) {
String latLongString = "Unknown";
String addressString = "No address found";
DecimalFormat df = new DecimalFormat("##.00");
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latLongString = "Lat:" + df.format(lat) + "\nLong:" + df.format(lng);
Geocoder gc = new Geocoder(MainActivity.this, Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(lat, lng, 1);
if (addresses.size() == 1) {
addressString="";
Address address = addresses.get(0);
addressString = addressString + address.getAddressLine(0) + "\n";
for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
addressString = addressString + address.getAddressLine(i) + "\n";
}
addressString = addressString + address.getLocality()+ "\n";
addressString = addressString + address.getPostalCode()+ "\n";
addressString = addressString + address.getCountryName()+ "\n";
}
} catch (IOException ioe) {
Log.e("Geocoder IOException exception: ", ioe.getMessage());
}
}
accurity.setText("Your Current Position is:\n" + latLongString + "\n" + addressString);
ln.setText(""+lng);
lt.setText(""+lat);
}
}
我送我的纬度,经度,以C#代码映射(动态数据显示),并在地图上绘制点。 纬度是错误的代码(它接近我的位置,但不准确 虽然 from addressString我得到了准确的我的地址的建设和城市和国家 从gps和纬度得到的地址长得到从GPS,为什么它准确吗?
addresses = gc.getFromLocation(lat, lng, 1);
林repit,只有LAT是错误的,长的是完美的。 我会如此心存感激的人会发现这个答案是非常重要的谢谢
的LocationManager,尤其是在使用GPS提供商只,需要相当长的时间来获得高精确度(lat,lng)对。你可以检查精确度(location.getAccuracy())并等到它足够小。融合了GPS,WiFi,Cell,融合的位置提供商,??? (谷歌不会说)更快,更省电。看一看! – 2014-10-09 03:48:23
谢谢你,但是我能做些什么来改善我的生活?看我的编辑。长期是完美的,但纬度不是.. – 2014-10-09 03:49:55