使用 getJSON 进行 Google 地图 V3 地理编码查找

发布于 2025-01-04 02:02:20 字数 546 浏览 5 评论 0原文

我有一个与这里类似的问题:

using jquery.getJson with Google's GeoCoding HTTP服务

但我尝试在不使用 API 密钥的情况下从客户端查找中检索地址的地理坐标。

使用此代码时似乎一切正常:

$.getJSON("http://maps.google.com/maps/api/geocode/json?address=202++3991+Henning+Dr+Burnaby+BC+V5C+6N5&sensor=false&callback=?",
  function(data, textStatus){
     console.log(data);
     console.log(textStatus);
});

但是,我收到“无效标签”jQuery 错误。

I have a question similar to here:

using jquery.getJson with Google's GeoCoding HTTP Service

with the exception that I'm trying to retrieve the geo-coordinates for an address without using the API key, from a client-side lookup.

Everything seems to work when using this code:

$.getJSON("http://maps.google.com/maps/api/geocode/json?address=202++3991+Henning+Dr+Burnaby+BC+V5C+6N5&sensor=false&callback=?",
  function(data, textStatus){
     console.log(data);
     console.log(textStatus);
});

However, I'm getting an 'invalid label' jQuery error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

伊面 2025-01-11 02:02:20

V3 地理编码 API 不支持回调参数,因此您尝试进行的 JSONP 调用将不起作用。相反,您可以使用 JavaScript API 并使用地理编码服务或通过代理结果您的网络服务器(以解决跨站点问题)。

The V3 geocoding API doesn't support the callback parameter, so the JSONP call you're trying to make won't work. Instead you could use the JavaScript API and use the Geocoding Service or proxy the results through your web server (to get around the cross-site issues).

无名指的心愿 2025-01-11 02:02:20

由于同源政策,您无法直接使用网络服务。

幸运的是,有一个解决方案:Maps API V3 中的地理编码服务

You can't use the web service directly because of same origin policy.

Lucky, there is a solution: The Geocoding Service in the Maps API V3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文