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
Solved! Go to Solution.
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);
});
});
});
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);
});
});
});
I'm not getting success from Console when I click the button on JS Bin.
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.