<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Geocode takes a crazy amount of time to respond in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1715944#M75342</link>
    <description>&lt;P&gt;I have a spot where I do something similar (using reverse_geocode) and it's not too slow for me:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;...

    def update_addresses(self, demand_feats: FeatureClass[PointGeometry, Demand_Point]) -&amp;gt; dict[int, str]:
        updates: dict[int, str] = {}
        with demand_feats.where("ADDRESS_FULL IS NULL OR ADDRESS = '0 UNKNOWN ADDRESS'"):
            need_address = list(demand_feats)

        if need_address:
            SetProgressorLabel('Getting Addresses from AGOL...')
            _ = GIS()
            updates = {
                d['OID@']: (
                    reverse_geocode(
                        json.loads(d['SHAPE@'].JSON),  # type: ignore
                        distance=30.0,
                        location_top='street',
                    )['address']['LongLabel'] or '0 UNKNOWN ADDRESS').upper()
                for d in need_address
            }
        return updates&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe that having an initialized GIS object is important. Since you need to have creds to use the geocoding service. Your dev machine is probably using your creds, but maybe Azure isn't?&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jul 2026 20:02:00 GMT</pubDate>
    <dc:creator>HaydenWelch</dc:creator>
    <dc:date>2026-07-22T20:02:00Z</dc:date>
    <item>
      <title>Geocode takes a crazy amount of time to respond</title>
      <link>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1715643#M75341</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# 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)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT: If run from my development machine, this code executes almost instantaneously. So possibly a communication issue between Azure and ArcGIS Online?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2026 20:36:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1715643#M75341</guid>
      <dc:creator>RogerAsbury</dc:creator>
      <dc:date>2026-07-22T20:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: Geocode takes a crazy amount of time to respond</title>
      <link>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1715944#M75342</link>
      <description>&lt;P&gt;I have a spot where I do something similar (using reverse_geocode) and it's not too slow for me:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;...

    def update_addresses(self, demand_feats: FeatureClass[PointGeometry, Demand_Point]) -&amp;gt; dict[int, str]:
        updates: dict[int, str] = {}
        with demand_feats.where("ADDRESS_FULL IS NULL OR ADDRESS = '0 UNKNOWN ADDRESS'"):
            need_address = list(demand_feats)

        if need_address:
            SetProgressorLabel('Getting Addresses from AGOL...')
            _ = GIS()
            updates = {
                d['OID@']: (
                    reverse_geocode(
                        json.loads(d['SHAPE@'].JSON),  # type: ignore
                        distance=30.0,
                        location_top='street',
                    )['address']['LongLabel'] or '0 UNKNOWN ADDRESS').upper()
                for d in need_address
            }
        return updates&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I believe that having an initialized GIS object is important. Since you need to have creds to use the geocoding service. Your dev machine is probably using your creds, but maybe Azure isn't?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2026 20:02:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1715944#M75342</guid>
      <dc:creator>HaydenWelch</dc:creator>
      <dc:date>2026-07-22T20:02:00Z</dc:date>
    </item>
    <item>
      <title>Re: Geocode takes a crazy amount of time to respond</title>
      <link>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1715960#M75343</link>
      <description>&lt;P&gt;My apologies, a GIS() line was in the code, but got trimmed by my overzealous trimming of potential security ids. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I've re-added it to the code.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2026 20:37:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1715960#M75343</guid>
      <dc:creator>RogerAsbury</dc:creator>
      <dc:date>2026-07-22T20:37:36Z</dc:date>
    </item>
    <item>
      <title>Re: Geocode takes a crazy amount of time to respond</title>
      <link>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1716087#M75344</link>
      <description>&lt;P&gt;Ok, after spending all day on this, here is what I found and how I fixed it:&lt;BR /&gt;First, logic to get timing on what, exactly, was going on when trying to get geocode, resulting in the following text:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;2026-07-23T00:01:05   [Information]   locateIssue geocoder resolution time: 1621.485s, geocoder: https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer
2026-07-23T00:01:05   [Information]   locateIssue geocode call time: 0.395s&lt;/LI-CODE&gt;&lt;P&gt;Which indicated the bulk of the time was spent determining the geocoder. Once found, the call to it was super fast.&lt;/P&gt;&lt;P&gt;Set that URL as the default geocoder, and everything went quickly.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;My assumptions:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;When setting gis = GIS(url, username, password) the url variable points to our segment of ArcGIS Online (entity.maps.arcgis.com), which doesn't have(?) a default geocoder, or doesn't point to one, or something...&lt;/LI&gt;&lt;LI&gt;By providing a good url, there is no need to look one up, saving time.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I don't really see anything in the geocode() documentation mentioning any of this (&lt;A href="https://developers.arcgis.com/python/latest/api-reference/arcgis.geocoding.html#geocode" target="_blank"&gt;arcgis.geocoding module | ArcGIS API for Python | Esri Developer&lt;/A&gt;) but maybe I missed it.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2026 00:36:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/geocode-takes-a-crazy-amount-of-time-to-respond/m-p/1716087#M75344</guid>
      <dc:creator>RogerAsbury</dc:creator>
      <dc:date>2026-07-23T00:36:34Z</dc:date>
    </item>
  </channel>
</rss>

