【问题标题】:how to tweak zoom (respectively Country, city, street...) in google map?如何在谷歌地图中调整缩放(分别为国家、城市、街道......)?
【发布时间】:2014-11-06 19:44:33
【问题描述】:

我在我的应用程序中使用谷歌地图。

在我的应用程序中,用户可以输入任何地址,之后该地址将在地图上找到,标记将设置在该位置。

如果我输入 CANADA,我想要那个 - 我会看到大约完整的国家

如果我输入 Toronto - 我会看到大约全城

如果我输入了街道 - 我想放大街道等等。

有可能实现吗?

附言

我想这样实现:https://www.google.ru/maps

  1. 尝试输入 USA
  2. 尝试输入 达拉斯
  3. 尝试输入 达拉斯市政厅

【问题讨论】:

  • 是的。地理编码器返回建议的视口和/或边界。您现有的代码是什么样的?你在使用地理编码器吗?
  • 你能举个例子吗?
  • @geocodezip 你能提供解释和代码片段的答案吗?
  • 你看不到这些例子的来源?

标签: javascript google-maps google-maps-api-3


【解决方案1】:

它正在工作:

    ....
    var place = autocomplete.getPlace();
    if (!place.geometry) {
      return;
    }

    // If the place has a geometry, then present it on a map.
    if (place.geometry.viewport) {
      map.fitBounds(place.geometry.viewport);
    } else {
      map.setCenter(place.geometry.location);
      map.setZoom(17);  // Why 17? Because it looks good.
    }
     ...

取自https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

【讨论】:

    猜你喜欢
    • 2012-07-05
    • 1970-01-01
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多