【问题标题】:Show full country on google map even if there is only one pin即使只有一个图钉,也可以在谷歌地图上显示完整的国家
【发布时间】:2014-09-27 13:09:03
【问题描述】:

我在我的 wordpress 网站上渲染地图时遇到了一些问题,我想要的是即使只有一个图钉,地图也应该显示该国家的完整地图,而不是放大版本,例如

假设这就是目前我的地图显示丹麦的方式

https://www.diigo.com/item/image/4id3g/j83y

我希望它像这样完整地显示国家/地区

https://www.diigo.com/item/image/4id3g/ay7d

但我不知道该怎么做,谁能帮帮我?

【问题讨论】:

  • 你的代码是什么样的?

标签: jquery google-maps google-maps-api-3 wordpress


【解决方案1】:

使用丹麦的边界(可以从地理编码器中检索)或根据需要创建自己的边界,然后使用 map.fitBounds 与该边界。

geocoder.geocode( { 'address': "Denmark"}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    if (results[0].geometry.viewport) 
      map.fitBounds(results[0].geometry.viewport);
  } else {
    alert("Geocode was not successful for the following reason: " + status);
  }
});

working fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-16
    • 2016-01-03
    • 1970-01-01
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    • 2011-03-14
    • 2021-05-22
    相关资源
    最近更新 更多