如何为Google Places API启用CORS

如何为Google Places API启用CORS

问题描述:

我已尝试一切可能使我的应用程式无需「启用Chrome的CORS扩充功能」。我按照谷歌官方网站上的步骤,谈到authtokens,尝试使用每个不同的键,但没有什么作品。我收到以下错误:

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无法加载 https://maps.googleapis.com/maps/api/place/nearbysearch/json? key = MyKey& location = 33.854546,-84.35870369999999& types = restaurant& rankby = distance。在所请求的资源上没有Access-Control-Allow-Origin

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.

甚至可以存取Google地方资讯,因此 http:// localhost:8100 API

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

您可以使用JSONP来完成任务,而不是CORS

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

请先阅读以下内容: Link1 Link2

Please read the following to get started: Link1, Link2