How to avoid Cross Domain problem when trying to use ArcGIS Online Geocode server?

4999
7
01-09-2015 07:44 AM
ab1
by
Occasional Contributor II

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?

0 Kudos
7 Replies
ab1
by
Occasional Contributor II

I'm using ArcGIS Online services exclusively. I don't have a server. So I can't create a server proxy.

0 Kudos
HeikoHeijenga
Esri Contributor

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)

0 Kudos
ab1
by
Occasional Contributor II

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.

0 Kudos
Venkata_RaoTammineni
Occasional Contributor

did you try to add crossdomain.xml in your webserver and your project ? try this option..

0 Kudos
ab1
by
Occasional Contributor II

I'm developing using salesforce and ArcGIS Online. I don't have access to any webserver.

0 Kudos
HeikoHeijenga
Esri Contributor

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.

0 Kudos