我正在尝试从我的本地主机计算机执行获取请求(并且我的应用程序将保留在本地主机上)以获取有关某个地点的一些信息。
但是,由于 CORS,Google Places API 和/或我的 Chrome 不允许我执行此请求(XMLHttpRequest 无法加载 https://maps.googleapis.com/maps/api/place/details/json?placeid=[placeid]&key=[key]。请求的资源上不存在“Access-Control-Allow-Origin” header 。因此不允许访问源“http://localhost:8080”。
).
是否有某种方法(无需 CORS Chrome 插件)可以从 Google Places API 获取访问权限?
我只是在 Javascript 中使用 Vue2 和 Vue 资源的简单 GET 请求:
this.$http.get(`https://maps.googleapis.com/maps/api/place/details/json?placeid=${googleplacesPlace}&key=${googleplacesToken}`).then(response => {
})
最佳答案
const PROXY_URL = 'https://cors-anywhere.herokuapp.com/';
const TARGET_URL = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?&key=KEY'
const URL = PROXY_URL + TARGET_URL
你可以用它来绕过cors。
关于javascript - Google Places API 相关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45185061/