Android 台灣中文網
標題:
經緯度轉成地址
[打印本頁]
作者:
chihhao81
時間:
2013-12-27 19:59
標題:
經緯度轉成地址
想請問高手:
我用網路上的範例程式,
將經緯度轉成地址,
可是把得到的地址貼到Google Map上,
跟我所在的地點都有段距離,
大概差距40~300公尺,
請問這樣的差距是正常的嗎?
取得經緯度
private void getLocation(Location location) { //將定位資訊顯示在畫面中
if(location != null) {
TextView longitude_txt = (TextView) findViewById(R.id.longitude);
TextView latitude_txt = (TextView) findViewById(R.id.latitude);
TextView address_txt = (TextView) findViewById(R.id.address);
Double longitude = location.getLongitude(); //取得經度
Double latitude = location.getLatitude(); //取得緯度
longitude_txt.setText(String.valueOf(longitude));
latitude_txt.setText(String.valueOf(latitude));
address_txt.setText(getAddressByLocation(location));
}
else {
Toast.makeText(this, "無法定位座標", Toast.LENGTH_LONG).show();
}
}
轉成地址
public String getAddressByLocation(Location location) {
String returnAddress = "";
try {
if (location != null) {
Double longitude = location.getLongitude(); //取得經度
Double latitude = location.getLatitude(); //取得緯度
Geocoder gc = new Geocoder(this, Locale.TRADITIONAL_CHINESE); //地區:台灣
//自經緯度取得地址
List<Address> lstAddress = gc.getFromLocation(latitude, longitude, 1);
if (!Geocoder.isPresent()){ //Since: API Level 9
returnAddress = "Sorry! Geocoder service not Present.";
}
returnAddress = lstAddress.get(0).getAddressLine(0);
}
}
catch(Exception e) {
e.printStackTrace();
}
return returnAddress;
}
作者:
lkk47
時間:
2013-12-30 00:28
有可能你得到的經緯度是正確的點 只是gps定位偏移了 我做過gps定位也會偏移 我上網查好像有偏移算法 但這我沒研究
作者:
mike110631
時間:
2014-1-6 11:29
在室內不精準 -> 合理
在室外不精準 -> 不太可能
作者:
lkk47
時間:
2014-1-9 20:18
你去下載 我的足跡 apk 看看有多精準 就知道了
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1