2

I'm trying to use Google elevation API with an AJAX request. It doesn't work and when I do console.log(ajax.responseText) I'm getting this error :

Cross-Origin Request Blocking: The Same Origin policy does not allow you to view the remote resource located at https://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536 , -104.9847034 & key = AIzaSyBXSbBWMZtGL2whXVC7T8wFhQcwcKGRuF4. Reason: The CORS header "Access-Control-Allow-Origin" is missing.

Does someone knows how to solve this problem ?

asked Apr 11, 2018 at 9:36

3 Answers 3

1

You can use a CORS proxy such as CORS-anywhere. A hosted CORS proxy can be found here (herokuapp.com). Usage is as follows (append location etc. yourself):

https://cors-anywhere.herokuapp.com/https://maps.googleapis.com/maps/api/elevation/json
answered Sep 7, 2018 at 17:21
0

If you are using cross domains open the web.config locate <httpProtocol> and add:

<httpProtocol>
 <customHeaders>
 <add name="Access-Control-Allow-Origin" value="*" />
 <add name="Access-Control-Allow-Credentials" value="true" />
 <add name="Access-Control-Allow-Methods" value="GET,POST,OPTIONS" /> 
 <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
 </customHeaders>
</httpProtocol>
answered Dec 15, 2018 at 20:09
0

A comment to this similar question on SO points to the Elevation API's documentation, which suggests to use the Maps JS API for client-side requests. It has a handy getElevationForLocations() method that should not throw a CORS error.

answered Sep 7, 2018 at 17:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.