Hello
I'm trying to use a javascript locator object with a geocode server of ArcGIS Online: http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_EU/GeocodeServer
When I call the method locator.addressToLocations(options)
, I get the cross-domain problem.
Is there a way to avoid this?
I'm using ArcGIS Online services exclusively. I don't have a server. So I can't create a server proxy.
sampleserver1 doesn't support CORS so you're out of luck. (also, you should only have a cross domain problem when the resulting URL will be more than 2000 characters long, in which case a POST request is made. If it's less a JSONP request is made which won't suffer from cross domain issues)
I tried using this example:
loc = new Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Geocode_USA/GeocodeServer");
var address = {"Single Line Input": "100 main street"};
var params = {address: address};
loc.outSpatialReference= map.spatialReference;
loc.addressToLocations(params, function(e){
console.log("success: " + e);
},
function(e){
console.log("error: " + e);
});
But I get in the console the cross-domain warning saying that the request was blocked.
I get also "success: ". Which mean that e is empty.
did you try to add crossdomain.xml in your webserver and your project ? try this option..
I'm developing using salesforce and ArcGIS Online. I don't have access to any webserver.
You don't have a cross domain problem... The fact that you get a "success: " mean your request came through but the geocoder just didn't find a match. The geocoder you use doesn't support single line address input. See Locator - JSFiddle for a working example.