问题
I have gone through several articles through this stack overflow and other related articles with reverse geocoding.
I have intended to find the name of the place with the given latitude and longitude from touch event. I got the latitude and longitude from the touch event but I couldn't get the address from that geo coordinate, it passes in the exception rather then being in the try area,
here is the code :
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;
}
}
please get me to the solution to it.
回答1:
so The emulator 2.2 has bug associated with Reverse Geocoding. So we need to download version like 2.1 and try. It will provide the desired result
回答2:
What exception do you get? Does you App have INTERNET permission? I'm pretty sure you'll need this for Geocoder to work (as it calls a Google Service via Internet).
来源:https://stackoverflow.com/questions/12555032/reverse-geocoding-in-android-with-touch-event