<?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 Error handling with addressToLocations in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302162#M27726</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using locator.addressToLocations to geocode an intersection name. My code is working great provided that the intersection name is valid and exists. However, if the address in invalid, the locator simply strips the address and geocodes the city and state. I'd like to catch these cases and handle them myself. (i.e. "Broadway &amp;amp; NoName St, Denver, CO could not be found") I can certainly identify cases where the address is empty in the candidate, but I can't find any reference to the original address I was trying to geocode while I'm in the showResults() function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pete&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;relevant snippet:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
function showAddress(aAddress, aWeight, aText) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; lLocator.outSpatialReference = lMap.spatialReference;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var options = {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; address:{ "SingleLine":aAddress },
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFields:["Loc_name","Match_addr"]
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; lLocator.addressToLocations(options);
}

function showResults(candidates) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; try {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var candidate;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.every(candidates, function (candidate) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(candidate.score + "|" + candidate.attributes.Match_addr);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Right here, I'd like to say, if (candidate.address == ""){alert("Bad address: " + candidate.attributes.Request_Address);}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // But Request_Address isn't something that exists.&amp;nbsp; How do I get it?
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (candidate.score &amp;gt; 80) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
}

function initMap() {
&amp;nbsp;&amp;nbsp;&amp;nbsp; lMap = new esri.Map("MyMapDiv", {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basemap:"streets", center:[-93.5, 41.431], zoom:5
&amp;nbsp;&amp;nbsp;&amp;nbsp; });

&amp;nbsp;&amp;nbsp;&amp;nbsp; lLocator = new esri.tasks.Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(lLocator, "onAddressToLocationsComplete", showResults);
&amp;nbsp;&amp;nbsp;&amp;nbsp; showAddress( "Broadway &amp;amp; NoName St, Denver, CO", 30, "This is the spot" );
}

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:19:05 GMT</pubDate>
    <dc:creator>Peted_Oronzio</dc:creator>
    <dc:date>2021-12-12T16:19:05Z</dc:date>
    <item>
      <title>Error handling with addressToLocations</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302162#M27726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm using locator.addressToLocations to geocode an intersection name. My code is working great provided that the intersection name is valid and exists. However, if the address in invalid, the locator simply strips the address and geocodes the city and state. I'd like to catch these cases and handle them myself. (i.e. "Broadway &amp;amp; NoName St, Denver, CO could not be found") I can certainly identify cases where the address is empty in the candidate, but I can't find any reference to the original address I was trying to geocode while I'm in the showResults() function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pete&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;relevant snippet:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
function showAddress(aAddress, aWeight, aText) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; lLocator.outSpatialReference = lMap.spatialReference;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var options = {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; address:{ "SingleLine":aAddress },
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outFields:["Loc_name","Match_addr"]
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; lLocator.addressToLocations(options);
}

function showResults(candidates) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; try {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var candidate;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.every(candidates, function (candidate) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(candidate.score + "|" + candidate.attributes.Match_addr);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Right here, I'd like to say, if (candidate.address == ""){alert("Bad address: " + candidate.attributes.Request_Address);}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // But Request_Address isn't something that exists.&amp;nbsp; How do I get it?
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (candidate.score &amp;gt; 80) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
}

function initMap() {
&amp;nbsp;&amp;nbsp;&amp;nbsp; lMap = new esri.Map("MyMapDiv", {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; basemap:"streets", center:[-93.5, 41.431], zoom:5
&amp;nbsp;&amp;nbsp;&amp;nbsp; });

&amp;nbsp;&amp;nbsp;&amp;nbsp; lLocator = new esri.tasks.Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
&amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.connect(lLocator, "onAddressToLocationsComplete", showResults);
&amp;nbsp;&amp;nbsp;&amp;nbsp; showAddress( "Broadway &amp;amp; NoName St, Denver, CO", 30, "This is the spot" );
}

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:19:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302162#M27726</guid>
      <dc:creator>Peted_Oronzio</dc:creator>
      <dc:date>2021-12-12T16:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling with addressToLocations</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302163#M27727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;this obviously wouldn't work when passing hardcoded addresses like in your example, but in a real app, couldn't you pull the information directly from the textbox?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;console.log("Bad address: " + dojo.byId("address").value);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;also, are you getting results from our world geocoding service for just city and state when you geocode "Broadway &amp;amp; NoName St, Denver, CO"?&amp;nbsp; i get zero candidates.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 08 Feb 2013 17:28:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302163#M27727</guid>
      <dc:creator>JohnGravois</dc:creator>
      <dc:date>2013-02-08T17:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling with addressToLocations</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302164#M27728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;this obviously wouldn't work when passing hardcoded addresses like in your example, but in a real app, couldn't you pull the information directly from the textbox?&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;console.log("Bad address: " + dojo.byId("address").value);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;also, are you getting results from our world geocoding service for just city and state when you geocode "Broadway &amp;amp; NoName St, Denver, CO"?&amp;nbsp; i get zero candidates.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have the same question, except I am geocoding a few locations in a row, and the data isn't on the page.&amp;nbsp; The geocoding process uses a callback, so I haven't been able to find a way to pass data along with it.&amp;nbsp; (even just a simple id would be great)&amp;nbsp; Now I'm just throwing it over the fence and hoping it works.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You know... I've been assuming the callback is asynchronous.&amp;nbsp; If it is synchronous, maybe I can set a global variable during the process.&amp;nbsp; But in that case, I don't understand why it would be a callback.&amp;nbsp; I figured it was to optimize the process by being asynchronous.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideas?&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pete&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 03:33:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302164#M27728</guid>
      <dc:creator>Peted_Oronzio</dc:creator>
      <dc:date>2013-09-04T03:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Error handling with addressToLocations</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302165#M27729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;i had to get some help from the awesome &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/16265"&gt;@MattDriscoll&lt;/a&gt; on this tricky (and interesting) question.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;it is possible to dig out your request parameters from the dojo.Deferred returned by the method (rather than relying on the response object which filters out just results).&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this is true not just for .addressToLocations(), but all asynchronous requests built upon the more generic &lt;/SPAN&gt;&lt;A href="https://developers.arcgis.com/en/javascript/jsapi/namespace_esri-amd.html#request" rel="nofollow noopener noreferrer" target="_blank"&gt;esri.request()&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
var promise = locator.addressToLocations(options);

promise.then(function(response) {
&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(promise._pendingDfd.ioArgs.args.content.SingleLine + ' wasnt a cool address.');
});
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:29:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/error-handling-with-addresstolocations/m-p/302165#M27729</guid>
      <dc:creator>JohnGravois</dc:creator>
      <dc:date>2021-12-11T14:29:28Z</dc:date>
    </item>
  </channel>
</rss>

