Hi, I am trying to print (geolocator.reverse('40.759516, -73.955443', distance='100')) on an location without an address within the distance parameter. I want to iterate through a list of locations, and store the locations that return a valid address. For example, if I run a iteration with coordinates over New York, I want to store all locations that actually have an address within the set distance. However, now, when there is no address within my set distance, I get an error:
Traceback (most recent call last):
File "./google.py", line 28, in <module>
location = geolocator.reverse(water, distance='100')
File "/home/strix/anaconda3/lib/python3.5/site-packages/geopy/geocoders/arcgis.py", line 202, in reverse
raise GeocoderServiceError(str(response['error']))
geopy.exc.GeocoderServiceError: {'code': 400, 'message': 'Cannot perform query. Invalid query parameters.', 'details': ['Unable to find address for the specified location.']}
Any ideas how to write a code that can handle such an error? Is it even possible since my script actually crashes (I am quite new to python, so please excuse any noob language).
My code:
from geopy.geocoders import ArcGIS
geolocator = ArcGIS()
location = geolocator.reverse('40.759516, -73.955443', distance='100')
print (location)
Thanks,
Nils
Hi Nils
You might get better support sticking to 'unwrapped' approaches, i.e. vanilla Python calling Esri's REST API natively. For example you can leverage the code in this sample to help with your reverse geocoding problem:
http://www.arcgis.com/home/item.html?id=da9efbe1232f426ead182213f53c8cd8
Be aware storing the results of ArcGIS Online geocoding or reverse geocoding requires service credits; in the sample the user token is picked up from the app but you can do it standalone with the generateToken call.
Regards
The coordinate you entered was in Antactica, if you are looking in New York this works but you need a search distance of 1000 metres as its in the river:
-73.955443,40.759516
Hi,
Thank you for the help. I will definitely look into using the native Esri REST API. Thanks for providing a link. I am not sure I understand the part about credits, but Ill make sure to read up on it.
Best,
Nils