Google 地图 API 自动完成功能仅绑定到英国

发布于 2025-01-02 09:25:21 字数 1424 浏览 7 评论 0原文

可能的重复:
将 Google 地图自动填充功能仅限于英国地址

如果任何人使用 Google地图 API V3 的经验可以帮助我,我将不胜感激 - 我已经在这方面坚持了几个小时了。

我试图让我的自动完成功能仅返回英国地址(因为该网站位于英国),但我的代码无法正常工作,即使它看起来好像我做得正确。我仍然收到所有其他国家的建议。

这是我的自动完成代码:

<script type="text/javascript">
  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(-0.12800500000003012, 51.508129),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var bounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(49.00, -13.00),
    new google.maps.LatLng(60.00, 3.00));

    var input = document.getElementById('sei');
    var autocomplete = new google.maps.places.Autocomplete(input);

    autocomplete.setBounds(bounds);

  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

我不确定从哪里获取边界 - 我在论坛上找到了上面的代码,但不确定它们是否 100% 正确。

下面是我的 API 包括:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=places,geometry&sensor=false&region=GB&gl=gb"></script>

如您所见,我在查询字符串中设置了区域和 gl。如果您看到下面的图片,您就会看到我的结果。是的,它稍微偏向英国 - 但仍然有洛杉矶出现。

在此处输入图像描述

任何帮助将不胜感激!

Possible Duplicate:
limiting google maps autocomplete to UK address only

If anyone with Google Maps API V3 experience can help me out it would be much appreciated - I've been stuck on this for hours.

I'm trying to get my autocomplete to return UK addresses only (because the site is based in the UK), but my code isn't working even though it appears as though I've done it right. I still get all other countries as suggestions.

Here's my autocomplete code:

<script type="text/javascript">
  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(-0.12800500000003012, 51.508129),
      zoom: 13,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var bounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(49.00, -13.00),
    new google.maps.LatLng(60.00, 3.00));

    var input = document.getElementById('sei');
    var autocomplete = new google.maps.places.Autocomplete(input);

    autocomplete.setBounds(bounds);

  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

I'm not sure where to get bounds from - I have found the ones above on a forum but am not sure if they're 100% correct.

Below is my API include:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=places,geometry&sensor=false®ion=GB&gl=gb"></script>

As you can see I have set a region and gl in the querystring. If you see my image below, you'll see the result I have. Yes, it's slightly more biased to the UK - but there's still Los Angeles appearing.

enter image description here

Any help would be much appreciated!

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

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

发布评论

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

评论(2

明媚如初 2025-01-09 09:25:21

请记住,自动完成类中的 setBounds() 方法设置返回地点结果的首选区域。结果偏向不限于该领域

Bear in mind that the setBounds() method in the Autocomplete class will set the preferred area within which to return Place results. Results are biased towards, but not restricted to, this area.

独守阴晴ぅ圆缺 2025-01-09 09:25:21

您使用的边界似乎是错误的。试试这些:

(49.383639452689664,-17.39866406249996)

(59.53530451232491,8.968523437500039)

You're using the wrong bounds it appears. Try these out:

(49.383639452689664, -17.39866406249996)

(59.53530451232491, 8.968523437500039)

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