Select to view content in your preferred language

Why can't I get an address score when there is no error for my locator service?

3416
3
Jump to solution
07-17-2015 01:48 PM
ChrisSergent
Deactivated User

I am attempting to evaluate a field and get a list of scores from address candidates when I use my address locator service. I receive no errors but it does not work as my console.log displays nothing.

Here is the code:

require(["esri/tasks/AddressCandidate",
                   "dojo/_base/array",
                    "esri/dijit/Search",
                    "esri/tasks/locator",
                    "dojo/on",
                    "dojo/dom",
                    "dojo/domReady!"], function (AddressCandidate, array, Search, Locator, on, dom) {


                        var locator = new Locator("http://maps.decaturil.gov/arcgis/rest/services/Public/WebAddressLocator/GeocodeServer");


                       on(dom.byId("btnTest"), "click", function () {
                           array.forEach(addressCandidates, function (candidate) {
                               if (candidate.score > score && candidate.attributes.Loc_name === document.getElementById("ownerAddress").value) {
                                   stop = candidate;
                                   score = candidate.score;
                                   // Display the score on the console.
                                   console.log(score);
                               }
                           });
                       });
                   });

You can see that Find Address Candidates is part of the Geocode Service here: Find Address Candidates: (Public/WebAddressLocator)

What do I need to change in my code to make it work?

And I have my most recent version of my code here: csergent45/codeViolationNotice at dbfa38b4cc3c87f3153a6137aaa7529b9bceddeb · GitHub

0 Kudos
1 Solution

Accepted Solutions
ReneRubalcava
Honored Contributor

You need to execute the locator first

JS Bin - Collaborative JavaScript Debugging

Something like this

require([
  'dojo/on',
  'esri/tasks/locator'
], function(on, Locator) {
  var locator = new Locator("http://maps.decaturil.gov/arcgis/rest/services/Public/WebAddressLocator/GeocodeServer");
  on(document.getElementById('find'), 'click', function(e) {
    var node = document.getElementById('address');
    // according to your service it takes Single Line
    var params = {
      "Single Line Input": node.value
    };
    locator.addressToLocations(params).then(function(addressCandidates) {
      console.log('success', addressCandidates);
    }).otherwise(function(err) {
      console.log('somethings wrong', err);
    });
  });
});

View solution in original post

3 Replies
ReneRubalcava
Honored Contributor

You need to execute the locator first

JS Bin - Collaborative JavaScript Debugging

Something like this

require([
  'dojo/on',
  'esri/tasks/locator'
], function(on, Locator) {
  var locator = new Locator("http://maps.decaturil.gov/arcgis/rest/services/Public/WebAddressLocator/GeocodeServer");
  on(document.getElementById('find'), 'click', function(e) {
    var node = document.getElementById('address');
    // according to your service it takes Single Line
    var params = {
      "Single Line Input": node.value
    };
    locator.addressToLocations(params).then(function(addressCandidates) {
      console.log('success', addressCandidates);
    }).otherwise(function(err) {
      console.log('somethings wrong', err);
    });
  });
});
ChrisSergent
Deactivated User

I'm not getting success from Console when I click the button on JS Bin.

0 Kudos
ChrisSergent
Deactivated User

This worked. It turned out that the page performed a postback because of it being a .NET page. Once I added an UpdatePanel and a ContentTemplate, the page worked. Thanks.

0 Kudos