I've got a Azure function app that processes data from a non-Survey123 form. On of the questions on that form allows a person to enter an address, just a street, or a landmark. I'm using geocode() to get x:y coordinates of that location. It works, but it seem to take nearly a half-hour to complete, which is crazy. Below is the code and I'm wondering what I may have done wrong here. This is my first time using the geocode() functionality.
# Given a location and location type (not currently used), attempt to geocode the location
# and return the X,Y coordinates. If no coordinates can be found, return (0,0).
# NOTE: THIS IS CURRENTLY REALLY SLOW. I don't know if it's an ESRI thing or a code thing,
# but it takes nearly a half hour to geocode locations.
def locateIssue(location, locationType):
logging.error(f"Locating issue for location: {location}")
gis = GIS(url, user, passwd)
try:
logging.error(f"Attempting to geocode location: {location} of type: {locationType}")
extent_env = Envelope({
"xmin": -148.633333,
"ymin": 64.25,
"xmax": -143.883333,
"ymax": 65.45,
"spatialReference": {"wkid": 4326}
})
result = geocode(address=location, search_extent=extent_env, max_locations=1)
logging.error(f"Geocode result for location '{location}': {result}")
except Exception as e:
logging.error(f"Failed to geocode location: {location}. Error: {e}")
return (0, 0)
if result:
for item in result:
x = item['location']['x']
y = item['location']['y']
return (x, y)
logging.error(f"Failed to locate issue for location: {location}")
return (0, 0)
EDIT: If run from my development machine, this code executes almost instantaneously. So possibly a communication issue between Azure and ArcGIS Online?