hubertlo

Locator.addressesToLocations - any examples? Do I need a paid license?

Discussion created by hubertlo on Oct 17, 2012
Latest reply on Oct 23, 2012 by hubertlo
Is there any example on how to make locator.addressesToLocations work? I found the reference to it here http://help.arcgis.com/en/webapi/javascript/arcgis/help/jsapi/locator.htm but I cannot get it to work.

I am using the North America geocode server: http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_NA_10/GeocodeServer

Here are my 2 addresses:
2896 Acadia Rd, Vancouver, British Columbia, V6T 1S2, Canada
3400 Balaclava Street, Vancouver, British Columbia, V6L 2S6, Canada

Here is my code snippet. It never gets into the showBatchResults function.
locator = new esri.tasks.Locator("http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_NA_10/GeocodeServer");
dojo.connect(locator, "onAddressesToLocationsComplete", showBatchResults)
var manyaddresses = [{"OBJECTID":0,"SingleLine":dojo.byId("address1").value},{"OBJECTID":1,"SingleLine":dojo.byId("address2").value}];
        locator.outSpatialReference= map.spatialReference;
        var options = {
          addresses:manyaddresses
        }
locator.addressesToLocations(options);

function showBatchResults(candidates) { }


      <div id="leftPane" class="roundedCorners" dojotype="dijit.layout.ContentPane" region="left">
        Enter an input address and the application will use the sample address locator to return the location for 
        street addresses in the United States. 
        <br />
        <textarea type="text" id="address1"/>2896 Acadia Rd, Vancouver, British Columbia, V6T 1S2, Canada</textArea>
        <br />
        <textarea type="text" id="address2">3400 Balaclava Street, Vancouver, British Columbia, V6L 2S6, Canada</textarea>
        <br />
        <button dojotype="dijit.form.Button" onclick="locate()"> Locate</button> 
      </div>



I have looked into the call using Fiddler2 and I get this:
GET http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_NA_10/GeocodeServer/geocodeAddresses?addresses=%7B%22records%22%3A%5B%7B%22attributes%22%3A%7B%22SingleLine%22%3A%222896%20Acadia%20Rd%2C%20Vancouver%2C%20British%20Columbia%2C%20V6T%201S2%2C%20Canada%22%7D%7D%2C%7B%22attributes%22%3A%7B%22SingleLine%22%3A%223400%20Balaclava%20Street%2C%20Vancouver%2C%20British%20Columbia%2C%20V6L%202S6%2C%20Canada%22%7D%7D%5D%7D&f=json&outSR=%7B%22wkid%22%3A102100%7D&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback HTTP/1.1
Host: tasks.arcgisonline.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://127.0.0.1:8021/MiscEsriSamples/geocode.html


The result is Error code 400. Details: "Invalid URL". Or this if I do it on the browser:
{"error":{"code":400,"message":"Unable to complete  operation.","details":["Invalid URL"]}}

What am I missing? My alternative is to call addressToLocation 1 address at a time.

Outcomes