dear Readers,
I followed the example mentioned for amd esri/tasks/locator as Locator.
var geocodeLocator = new Locator("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
I created a function and the code inside the function was the following:
findAddress: function (streetAddress, countyFIPS, map) {
if (streetAddress.length === 0) {
alert('Please enter an address.');
return;
}
if (countyFIPS.length === 0) {
alert('County is needed.');
return; }
var searchAddress = { "Single Line Input": streetAddress }; // single element - not an array.
var options = {
address: searchAddress,
outFields: ["Loc_name"]};
geocodeLocator.outSpatialReference = map.spatialReference;
geocodeLocator.on("error", function (error) {
alert('Error code: [' + error.error.httpCode.toString() + '.] ' + error.error.message);
return;
});
geocodeLocator.on("address-to-locations-complete", function (addressCandidates) {
array.forEach(addressCandidates, function (eachAddressCandidate) {
var test = "";
console.log("results:" + results.toString());
});
});
geocodeLocator.addressToLocations(options);
}
{"spatialReference":{"wkid":102100,"latestWkid":3857},"candidates":[]}
getting an empty address candidates - let alone score . lat long...
any guidance will be greatly appreciated.
regards
ravi.
Solved! Go to Solution.
Ravi,
The field name for the single line field is SingleLine. You are trying to use the fields alias name:
findAddress: function (streetAddress, countyFIPS, map) {
if (streetAddress.length === 0) {
alert('Please enter an address.');
return;
}
if (countyFIPS.length === 0) {
alert('County is needed.');
return;
}
var searchAddress = { "SingleLine": streetAddress }; // single element - not an array.
var options = {
address: searchAddress,
outFields: ["Loc_name"]
};
geocodeLocator.outSpatialReference = map.spatialReference;
geocodeLocator.on("error", function (error) {
alert('Error code: [' + error.error.httpCode.toString() + '.] ' + error.error.message);
return;
});
geocodeLocator.on("address-to-locations-complete", function (addressCandidates) {
array.forEach(addressCandidates, function (eachAddressCandidate) {
var test = "";
console.log("results:" + results.toString());
});
});
geocodeLocator.addressToLocations(options);
}
Ravi,
The field name for the single line field is SingleLine. You are trying to use the fields alias name:
findAddress: function (streetAddress, countyFIPS, map) {
if (streetAddress.length === 0) {
alert('Please enter an address.');
return;
}
if (countyFIPS.length === 0) {
alert('County is needed.');
return;
}
var searchAddress = { "SingleLine": streetAddress }; // single element - not an array.
var options = {
address: searchAddress,
outFields: ["Loc_name"]
};
geocodeLocator.outSpatialReference = map.spatialReference;
geocodeLocator.on("error", function (error) {
alert('Error code: [' + error.error.httpCode.toString() + '.] ' + error.error.message);
return;
});
geocodeLocator.on("address-to-locations-complete", function (addressCandidates) {
array.forEach(addressCandidates, function (eachAddressCandidate) {
var test = "";
console.log("results:" + results.toString());
});
});
geocodeLocator.addressToLocations(options);
}
thanks Robert for your help. I got that information about "Singe Line Input" from esri help pages.
I changed it to singleLine and it worked.
regards
ravi.