0

I'm facing a very strange issue with respect to the esri.tasks.locator function. If I do a hard-refresh (Ctr+Shift+R), the map starts working without any error. But after that if just try to refresh again (normal F5), the console prints out

TypeError: esri.tasks.Locator is not a constructor

Then if I again do a hard-refresh, everything works normally. What could be the cause of this behavior? The code I'm using is as follows:

dojo.require("esri.map");
dojo.require("esri.tasks.locator");
.
.
.

var locator = new esri.tasks.Locator("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"); // this line is throwing error if not hard-refreshed
var params = {address:"200 E Berry St", maxLocations:1};
locator.addressToLocations(params);
locator.on("address-to-locations-complete", function (evt) { ... } );
1
1

Please use like this

require([
 "esri/tasks/locator"
], function (Locator) {
    var locator = new Locator("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"); // this line is throwing error if not hard-refreshed
    var params = {address:"200 E Berry St", maxLocations:1};
    locator.addressToLocations(params);
    locator.on("address-to-locations-complete", function (evt) { ... } );
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.