Using Locator in 4.5 api for geocoding

981
2
Jump to solution
11-08-2017 11:34 AM
JeffSauder
Occasional Contributor

I am trying without much success to geocode an address in my javascript application using the Locator.  I set up a geocode service, and tested that service successfully, but calling it from javascript returns nothing.  There really isn't much as far as samples for this Locator object (esri/tasks/Locator), so I'm hoping maybe someone has done this successfully and could share this info.

This is the function (with the address passed into val), as far as I can tell the parameters are passed in as an object, and the promise returns the value returned by the geocode service.  I just get a 0 length array when I do this.  (The city, "GILB", is an abbreviated city code that we use in our streets layer.  This works when querying the geocode service itself).

  var addr={
    "Street": val,
    "City": "GILB"
  }
  addLoc.outSpatialReference=view.spatialReference;
  addLoc.addressToLocations(addr).then(function(response) {
    console.log(response);
  })
  .otherwise(function(err) {
    window.alert(val + " Not Found (geo)");
  });

The response I get is the 0 length array, and not the "Not Found" dialog, so I think this is not creating an error, just not getting the value from the geocode service.

If anyone has had success with this, and would be willing to point me in the right direction, I would be grateful.

Thank you in advance for your assistance.

Jeff

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Jeff,

  Your issue in your code is that your object does not have an address property:

  var addr={
    "address": {
      "Street": val,
      "City": "GILB"
    }
  }

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Jeff,

  Your issue in your code is that your object does not have an address property:

  var addr={
    "address": {
      "Street": val,
      "City": "GILB"
    }
  }
JeffSauder
Occasional Contributor

That was it, Robert.  An oversight on my part I guess.  Thank you so much, it works now

0 Kudos