Using ArcGIS JavaScript API 3.19 I am trying to do a bulk reverse geocoding like
var locator = new Locator("http://dummydomain:6080/arcgis/rest/services/TestGeocoder/GeocodeServer");
map.on("load", function(evt) {
var points= [{
"x": -83.000369,
"y": 40.055185
}, {
"x": -83.000031,
"y": 40.051250
}];
locator.outSpatialReference = map.spatialReference;
var options = {addresses: points};
locator.locationToAddress(options);
});
I am not getting any error on page but the map screen looks empty! can you please let me know what I am doing wrong? and how I can export the points address to console? Thanks
Solved! Go to Solution.
Bengi,
In your code you are using:
webMercatorUtils.webMercatorToGeographic(-83.000369,40.055185)
webMercatorUtils.webMercatorToGeographic is expecting a geometry, not a string and for that matter you are providing a lat lon so it is already geographic. So there is no need to use webMercatorUtils.webMercatorToGeographic. You need to use something like:
locator.locationToAddress(new Point(-83.000369,40.055185, new SpatialReference({ wkid: 4326 })), 100);
Bengi,
There is no bulk reverse geocoding ability. The method is locationToAddress (singular not plural). The best you can do is use a promise all.
Thanks for reply Robert,
The promise all looks very complicated! In order to get a better understanding, can you please let me know why this code also not working?!
$('#locator').on("click", function() {
locator.outSpatialReference = map.spatialReference;
locator.locationToAddress(webMercatorUtils.webMercatorToGeographic(-83.000369,40.055185), 100);
});
As you can see I am only passing X and Y of one single location to locationToAdress()! and in return I am getting this error
dojo.io.script error Error: Unable to complete operation.
at Object.f.load (init.js:980)
at init.js:87
at c (init.js:103)
at d (init.js:103)
at b.Deferred.resolve.callback (init.js:105)
at c (init.js:104)
at d (init.js:103)
at b.Deferred.resolve.callback (init.js:105)
at init.js:996
at h (init.js:107)
Bengi,
In your code you are using:
webMercatorUtils.webMercatorToGeographic(-83.000369,40.055185)
webMercatorUtils.webMercatorToGeographic is expecting a geometry, not a string and for that matter you are providing a lat lon so it is already geographic. So there is no need to use webMercatorUtils.webMercatorToGeographic. You need to use something like:
locator.locationToAddress(new Point(-83.000369,40.055185, new SpatialReference({ wkid: 4326 })), 100);
Thanks Again Robert,
Just one final question
As you said the locator is functioning now but when I try to get the address like this
locator.locationToAddress(new Point(-83.000369,40.055185, new SpatialReference({ wkid: 4326 })), 100);
console.info(locator.address.Street);
console.info(locator.Street);
I am just getting undefined in return! isn't it the address available through the locator object?
Bengi,
The locator returns a deferred object to the callback function or the location-to-address-complete event function that you have set for the Locator object. So no you can not get the result the way you are trying.
locator.locationToAddress(new Point(-83.000369,40.055185, new SpatialReference({ wkid: 4326 })), 100, function(event){
console.info(event.address);
});