我已經通過這篇堆棧溢出和其他反向地理編碼的相關文章瞭解了幾篇文章。在Android中使用觸摸事件進行反向地理編碼
我打算從觸摸事件中找到具有給定經度和緯度的地點的名稱。我從觸摸事件的緯度和經度,但我無法從地理地址座標,它通過在異常而不是在嘗試區域之中,
這裏是代碼:
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
//---when user lifts his finger---
//---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Toast.makeText(getBaseContext(),
p.getLatitudeE6()/1E6 + "," +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(p.getLatitudeE6()/1E6, p.getLongitudeE6()/1E6, 1);
String strCompleteAddress= "";
if (addresses.size() > 0)
{
for (int i=0; i<addresses.get(0).getMaxAddressLineIndex();i++)
strCompleteAddress+= addresses.get(0).getAddressLine(i) + "\n";
}
Log.i("MyLocTAG => ", strCompleteAddress);
Toast.makeText(getBaseContext(), strCompleteAddress, Toast.LENGTH_LONG).show();
}
catch (IOException e) {
e.printStackTrace();
Toast.makeText(getBaseContext(), "exception", Toast.LENGTH_LONG).show();
}
return true;
}
else
return false;
}
}
請讓我來解決它。
我看到...我首先知道模擬器2.2有與反向地理編碼相關的錯誤...感謝您的體驗。 – BBonDoo