Link
Link

Reputation: 76

Google Maps geocoding service Access-Control-Allow-Origin error

I want to loop through an array of addresses and retrieve the lat-lng coordinates from Google geocoding before the page loads so I can have markers on all the addresses. When I attempt to do that though I get the Access-Control-Allow-Origin error.

Everyone suggests to use the geocoding API but I don't need anything dynamic. I already have the information I need when the webpage loads up.

var url = 
"http://maps.googleapis.com/maps/api/geocode/json?address="+address+"&sensor=true";

var request = new XMLHttpRequest();
request.open("GET", url, false);
request.send();

As you can see, the code is simple enough, but is there a way to get around the error while still using the http request?

Upvotes: 0

Views: 3997

Answers (1)

Mauricio A. Cinelli
Mauricio A. Cinelli

Reputation: 161

Just today I faced the same error as yours, and the solution is in this other question on SO

Origin url is not allowed by Access-Control-Allow-Origin with Google Direction API

As I saw, you now have to use the Geocoding API to search addresses, even if you have the specific address.

Hope this helps

Upvotes: 1

Related Questions