HTTP GET request to Google Maps directions API gives CORS error

4,652 views
Skip to first unread message

Amit Singh

unread,
Sep 24, 2017, 7:41:54 PM9/24/17
to Google Maps JavaScript API v3
Through angular js i'm making a $http.get request to the maps directions api and i'm getting this error 
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/directions/json?origin=12.9330966756336,77.6308643817902&destination=12.931329492531,77.6295876502991&mode=walking&sensor=false. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
What to do ? 

 

Andrew Leach

unread,
Sep 24, 2017, 7:50:31 PM9/24/17
to google-map...@googlegroups.com

The "preflight" failure appears to mean that Google does not allow requests from localhost, which is understandable as your implementation has to be public and localhost is private.

Thus a likely solution would be to host your implementation on a publicly-accessible server on a real domain.
Reply all
Reply to author
Forward
0 new messages