How to enable CORS for Google Places API

2019-04-22 03:00发布

问题:

I have tried everything possible to make my app work without the need for the "Enable CORS extension for Chrome". I followed the steps on Google's official website which talks of authtokens, tried using every different key, but nothing works. I get the following error:

XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=MyKey&location=33.854546,-84.35870369999999&types=restaurant&rankby=distance. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin http://localhost:8100 is therefore not allowed access.

Is it even possible to access Google Places API from inside an app, without the CORS extension for Chrome?

回答1:

Instead of CORS, you can use JSONP to accomplish your task.

Please read the following to get started: Link1, Link2