<?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: Geocoding list of Addresses in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371929#M83389</link>
    <description>&lt;P&gt;I think I know what's happening. When you send the locations to the geocoder, it returns a promise which is resolved whenever it is completed, which may or may not be in the order it was sent. So, the result list is jumbled. As for how to fix it... I don't know.&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jan 2024 21:08:52 GMT</pubDate>
    <dc:creator>JeffreyThompson2</dc:creator>
    <dc:date>2024-01-18T21:08:52Z</dc:date>
    <item>
      <title>Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371744#M83383</link>
      <description>&lt;P&gt;Hi everyone, I have created a functionality which allows users to upload an Excel file containing addresses and I'm then geocoding those addresses to get statistics within the buffer. My issue is that the order of my addresses changes when geocoding.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;          document.getElementById("done-button").onclick = () =&amp;gt; {
            var fileInput = document.getElementById('fileInput');
            var file = fileInput.files[0];

            if (file) {
              var reader = new FileReader();

              reader.onload = function (e) {
                var data = e.target.result;
                var workbook = XLSX.read(data, { type: 'binary' });
                var sheetName = workbook.SheetNames[0];
                var sheet = workbook.Sheets[sheetName];

                var dataArray = XLSX.utils.sheet_to_json(sheet, { header: 1 });
                list_address = dataArray.flat()
                uniqueAddressID2 = list_address
                const params=[]
                const geocode = "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer";
                for (var i = 0; i &amp;lt; list_address.length; i++) {
                  //const addressinput = list_address[i]
                  params[i] = {
                    address: {
                      address: list_address[i],
                    },
                    countryCode: "CAN",
                    outSpatialReference: SpatialReference.WGS84
                  };
                }

                for (var i = 0; i &amp;lt; params.length; i++) {
                  locator.addressToLocations(geocode, params[i]).then((results) =&amp;gt; {
                    if (results.length) {
                      const result = results[0];
                      const point = new Point({
                        x: result.location.x,
                        y: result.location.y,
                        spatialReference: { wkid: 4326 }
                      });
                      address_geo.push(point)
                      BatchBufferGeom(address_geo)
                    };
                  });
                
                
                };
              }
              
              reader.readAsBinaryString(file);
            } else {
              alert('Please select a file.');
            }
          }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 21:06:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371744#M83383</guid>
      <dc:creator>Charan</dc:creator>
      <dc:date>2024-01-18T21:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371870#M83387</link>
      <description>&lt;P&gt;Is the order based on a sorting definition for a particular field or set of fields? If not, you would have to reference the original order and copy each geocode row out individually in the order you want.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 19:58:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371870#M83387</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-01-18T19:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371887#M83388</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;so in the second for loop (see below). The list of addresses (params) is still in order but the results change it&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;for (var i = 0; i &amp;lt; params.length; i++) {&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 21:08:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371887#M83388</guid>
      <dc:creator>Charan</dc:creator>
      <dc:date>2024-01-18T21:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371929#M83389</link>
      <description>&lt;P&gt;I think I know what's happening. When you send the locations to the geocoder, it returns a promise which is resolved whenever it is completed, which may or may not be in the order it was sent. So, the result list is jumbled. As for how to fix it... I don't know.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 21:08:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371929#M83389</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2024-01-18T21:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371964#M83390</link>
      <description>&lt;P&gt;If you adjust the logic of how you are doing things a bit, you can create an array of promises and wait for them all to complete. It does require another loop to do your buffer, but this could help you maintain the order you are looking for.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const geocodePromises = params.map(
  (param) =&amp;gt; locator.addressToLocations(...)
);

Promise.all(geocodePromises).then((results) =&amp;gt; {
  // do something with results
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;Note, you can use &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all" target="_self"&gt;Promise.all&lt;/A&gt; or &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled" target="_self"&gt;Promise.allSettled&lt;/A&gt;. The result signatures are different, but depends on your needs.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 21:56:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371964#M83390</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2024-01-18T21:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371967#M83391</link>
      <description>&lt;P&gt;Are you sure they're in the right order when read into&amp;nbsp;&lt;FONT face="courier new,courier"&gt;list_address&lt;/FONT&gt; and&amp;nbsp;&lt;FONT face="courier new,courier"&gt;params&lt;/FONT&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 22:00:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371967#M83391</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-01-18T22:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371970#M83392</link>
      <description>&lt;P&gt;Ah, yes, good point! You would probably have to leverage the &lt;A href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await" target="_self"&gt;await operator&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 22:06:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1371970#M83392</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-01-18T22:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1372412#M83407</link>
      <description>&lt;P&gt;yup, I ran console.log on both and the order was correct&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 18:38:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1372412#M83407</guid>
      <dc:creator>Charan</dc:creator>
      <dc:date>2024-01-19T18:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1372438#M83409</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7384"&gt;@ReneRubalcava&lt;/a&gt;&amp;nbsp;I used the following code, however, I'm getting an error at location.x&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;                const geocodePromises = params.map(
                    (param) =&amp;gt; locator.addressToLocations(geocode, param)
                )
                Promise.all(geocodePromises).then((results) =&amp;gt; {
                  for(var i=0; i&amp;lt;results.length; i++) {
                    const result= results[i]
                    const point = new Point({
                      x: result.location.x,
                      y: result.location.y,
                      spatialReference: { wkid: 4326 }
                    });
                    console.log(result)
                    address_geo.push(point)
                    BatchBufferGeom(address_geo)
                  }&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Charan_0-1705691242777.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/92250iF867AE31E84D6133/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Charan_0-1705691242777.png" alt="Charan_0-1705691242777.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 19:07:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1372438#M83409</guid>
      <dc:creator>Charan</dc:creator>
      <dc:date>2024-01-19T19:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Geocoding list of Addresses</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1372500#M83410</link>
      <description>&lt;P&gt;This probably means there was not a result for that address, so you probably need to add some checks that you have a valid result.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 20:15:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/geocoding-list-of-addresses/m-p/1372500#M83410</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2024-01-19T20:15:26Z</dc:date>
    </item>
  </channel>
</rss>

