馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
想請問高手:
我用網路上的範例程式,
將經緯度轉成地址,
可是把得到的地址貼到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;
} |

|