esri tasks locator - not returning any records for single address

482
2
Jump to solution
02-14-2017 03:48 PM
Ravichandran_M_Kaushika
Occasional Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

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);
}

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

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);
}
Ravichandran_M_Kaushika
Occasional Contributor

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.

0 Kudos