使用Google Maps JavaScript API v3的Access-Control-Allow-Origin [英] Access-Control-Allow-Origin using Google Maps JavaScript API v3

查看:275
本文介绍了使用Google Maps JavaScript API v3的Access-Control-Allow-Origin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Google Maps JavaScript API v3( jobadvisor.scriptonite.be )(荷兰语).

I am currently writing a web application using Google Maps JavaScript API v3 (jobadvisor.scriptonite.be)(DUTCH).

该应用程序已经上线了几个月,并且一切正常.但是在本月初,我开始在本地主机中调整源代码.一周后,我更新了本地主机上的所有内容,并将其保留在那里.

The application is online for a couple of months now and everything was working just fine. But then at the start of this month, I started adjusting my source code in local host. After a week I updated everything on my localhost an left it there.

那么,FTR:

  • 我目前在在线主机上拥有旧的应用程序
  • 我在本地主机上更新的应用程序

然后两周过去了,但是现在,当我尝试获取位置(在应用程序中,最近的面包店)时,控制台返回错误:

Then 2 weeks went by, but now, when I try to GET a location(on the application, the closest bakery), the console returns the error:

XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=51.053…ance&types=bakery&sensor=false&key=AIzaSyDQOMaCyapoFRbaagiFUZ3qRGk1UJni7nk. 
Origin http://www.jobadvisor.scriptonite.be is not allowed by Access-Control-Allow-Origin.

所以错误绝对不是代码中的原因,旧应用程序的代码很好(它可以工作3个月),而更新后的应用程序在我离开它2周之前也可以工作.我认为Google已阻止了我的API密钥中的某种许可.

So the error is definitely not in the code, old application's code was fine(it worked for 3 months), and the updated application also worked before I left it for 2 weeks. I think Google has blocked some sort of permission in my API Key.

我认为跨域XMLHttpRequest 引发了错误,因为发送和接收数据没有相同的原始政策. Google不再允许我使用此API密钥进行访问.我已经读到有关托管应用程序的网站必须位于代理服务器上的信息,但这对我来说是没有选择的.

I think the error is raised by Cross-Origin XMLHttpRequest because the send and receive data don't have the same origin policy. Google doesn't allow access anymore on this my API-key. I've read something about that your site, hosting the app, has to be on a proxy-server, but that's no option for me...

有人知道如何防止此错误吗?

Does anybody know how to prevent this error?

推荐答案

@ Dr.Molle的答案:

Answer by @Dr.Molle:

使用places-library在客户端请求places-result: https://developers.google.com/maps/documentation/javascript/places#place_search_requests

Use the places-library to request places-results on clientside: https://developers.google.com/maps/documentation/javascript/places#place_search_requests

这篇关于使用Google Maps JavaScript API v3的Access-Control-Allow-Origin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆