Did you install the development branch, as it mentioned in the link you provided?
The reverse geocoding feature is currently in an experimental but
stable development branch, which you can checkout here:
svn checkout http://geopy.googlecode.com/svn/branches/reverse-geocode
geopy
cd geopy/ sudo
python setup.py install
You may have to delete your old geopy installation.
First, try setting the distance to 50 locator.reverseGeocode(mapPoint, 50);
.
The PlaceSearch sample already does the specific feature you are trying to implement. The current implementation geocodes the address, or place, in the edit text field after you hit the Go button. Then when you click on the blue graphic representing the result a callout appears with the gecode result. Look at the setOnSingleTapListener
method on the MapView
to see this implementation.
Here is a simple workflow to implement reverse geocoding which returns an address to an Android Toast anywhere on the map.
Create an AsyncTask to Reverse Geocode off the UI thread
private class ReverseGeocodeTask extends
AsyncTask {
@Override
protected LocatorReverseGeocodeResult doInBackground(Point... params) {
// create results object and set to null
LocatorReverseGeocodeResult result = null;
// set the geocode service
locator = new Locator();
try {
// Attempt to reverse geocode the point.
// Our input and output spatial reference will be the same as the map.
SpatialReference mapRef = mMapView.getSpatialReference();
result = locator.reverseGeocode(params[0], 50,
mapRef,
mapRef);
} catch (Exception e) {
e.printStackTrace();
}
// return the resulting point(s)
return result;
}
protected void onPostExecute(LocatorReverseGeocodeResult result) {
String resultAddress = "";
// Construct a nicely formatted address from the results
StringBuilder address = new StringBuilder();
if (result != null && result.getAddressFields() != null) {
Map addressFields = result.getAddressFields();
address.append(String.format("%s\n%s, %s %s",
addressFields.get("Address"), addressFields.get("City"),
addressFields.get("Region"), addressFields.get("Postal")));
// Show the results of the reverse geocoding in a toast.
resultAddress = address.toString();
Toast toast = Toast.makeText(PlaceSearchActivity.this,
resultAddress, Toast.LENGTH_LONG);
toast.show();
}
}
}
Then implement setOnLongPressListener
on the MapView onCreate
method
mMapView.setOnLongPressListener(new OnLongPressListener() {
private static final long serialVersionUID = 1L;
@Override
public void onLongPress(float x, float y) {
Point mapPoint = mMapView.toMapPoint(x, y);
new ReverseGeocodeTask().execute(mapPoint);
}
});
You can find more reference on Reverse geocoding from the ArcGIS Online Geocoding Service here.
Best Answer
Don't use an external command to set your proxy. If you are on Windows and your proxy is already setup in your internet options, you don't need to set it up in the script at all, it will be autodetected.
If you don't have a proxy already set up, you can pass the proxy directly to the geocoder:
Or you can set the proxy as an environment variable without an external command:
Then you can access the returned address like:
Output:
If you want to extract the country name and post code, have a look in the
location.raw
dictionary. The response components are specified in the Google API documentation.Note this is only applicable to the GoogleV3 geocoder and subject to breakage if Google changes their API...
Note - Google doesn't appear to return the continent name.