Select to view content in your preferred language

Address Locator does nothing

571
1
04-05-2010 11:10 AM
DouglasGreenfield
Occasional Contributor
I'm fairly inexperienced with JavaScript so I set up a web site by mostly copying and pasting from examples. Everything works great except for calling the address locator. I know my locator is fine because when I go to my ArcGIS Services Directory, choose the locator service and click "Find Address Candidates", it finds the expected candidates. However, in the code it does nothing. I put an OnError statement for the dojo connect and I get an error but don't know how to use that error to get anything useful. The JavaScript console in firefox lists no errors and without that onError, nothing happens when I try locating my address.
Here are the  relevant parts of the code - it is just copied from other's examples. The syntax of my locator is correct as far as I can tell. The locator is a US One Range - all address info is in one field (Street). The address info comes from two user inputs - I have tested those and they work fine for setting the "useraddr" variable.

locator = new esri.tasks.Locator("http://192.9.220.144/Newtonweb/rest/services/Locators/AddressNoZip/GeocodeServer");

   
        dojo.connect(locator, "onAddressToLocationsComplete", showResults);
        dojo.connect(locator, "onError", error);

function locate() {
        map.graphics.clear();

        var useraddr = dojo.byId("streetnum").value + " " + dojo.byId("streetname").value;
       
        var address =
          {
          Street: useraddr
          };

        locator.addressToLocations(address);

      }

in the <body>:
<input type="button" value="Locate" onclick="locate()" />
0 Kudos
1 Reply
MicahWilliamson
Frequent Contributor
First let me tell you that ESRI Tech support ofr the Javascript API is fantastic. they are really making an effort to make it work for everyone.

that being said, here is my geocode locator code. I also have use a US one range for my locator with one field "Street:" the problem is that the sample uses a field called "Address:" which is also the name of their variable in the JavaScript for the user entry box. So I get confused very easy. 🙂

after the close of the init{} part this is what i have.

      function locate() {
        map.graphics.clear();
        var add = dojo.byId("address").value.split(",");

        var address = { Street: add[0] };


        locator.addressToLocations(address,["Loc_name"]);
      }

      function showResults(candidates) {
        var candidate;
        var symbol = new esri.symbol.SimpleMarkerSymbol();
        var infoTemplate = new esri.InfoTemplate("Location", "Street: ${address}<br />Score: ${score}<br />Side: ${side}");

_____the code moves  on here but that's all i changed______

you can see where i put the "Street:" field in replacement of the Sample's "Address:"

I hope that works, i am not a programmer either. but i have to play one at work.

-Micah
0 Kudos