我試圖讓我的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