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

1674
3
10-17-2012 06:59 AM
HubertLo
New Contributor
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.
0 Kudos
3 Replies
TracySchloss
Frequent Contributor
The locator services are not interchangeable.  Each service has different inputs and outputs and you need to look at each service to see what input each locator is expecting.  the TA_Address_NA Geocoder Server doesn't accept a singleLine input like you've specified.  It expects separate input for address, city, state, zip. 

If you want to use a single line input, I suggest you use the World Locator geocoder server, http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer
0 Kudos
derekswingley1
Frequent Contributor
Batch geocoding via the JS API requires a 10.1 service, as noted in the API reference for addressesToLocations.
0 Kudos
HubertLo
New Contributor
Thank you Derek for the clarification.

I guess the http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_NA_10/GeocodeServer is using version 10.04 based on the version shown in 1 page up. Is there any plan to upgrade it to ver 10.1 soon?

What other ESRI public Locators out there I can use (without paying) that can support this batch geocoding? Currently I need the North American addresses. It does not has to be SingleLine as long as I know what parameters I need to use.
0 Kudos