0

我的问题是 fitBounds 通常使对象居中但太小。我希望它应该将地图集中在某个对象上并尽可能放大。事实上,缩放级别通常可以高一级。请考虑我的例子。如您所见,该国家/地区可以放大一级并且仍然 100% 可见。有什么办法可以克服吗?

这是我的代码:

$(document).ready(function(){

  var locationBBOX = [["14.149166 49.002914","24.14444 49.002914","24.14444 54.834442","14.149166 54.834442","14.149166 49.002914"]];


  var map = new google.maps.Map(
      document.getElementById('map-div'), {
      center: new google.maps.LatLng(0, 0),
      disableDefaultUI: true,
      zoom: 1,
      mapTypeId: google.maps.MapTypeId.ROADMAP });

  var _bounds = new google.maps.LatLngBounds();

  for(var k in locationBBOX)
  {

    var _c1 = locationBBOX[k][0].split(' ');
    var _c2 = locationBBOX[k][2].split(' ');

    var _bbox = new google.maps.LatLngBounds(new google.maps.LatLng(parseFloat(_c1[1]),parseFloat(_c1[0])),new google.maps.LatLng(parseFloat(_c2[1]),parseFloat(_c2[0])));

    _bounds.union(_bbox);
  }

  map.fitBounds(_bounds);

  var ne = _bounds.getNorthEast();
  var sw = _bounds.getSouthWest();

  var boundingBoxPoints = [
                       ne, new google.maps.LatLng(ne.lat(), sw.lng()),
                       sw, new google.maps.LatLng(sw.lat(), ne.lng()), ne
                    ];

  var boundingBox = new google.maps.Polyline({
                       path: boundingBoxPoints,
                       strokeColor: '#FF0000',
                       strokeOpacity: 1.0,
                       strokeWeight: 2
                    });

  boundingBox.setMap(map);


});

谢谢!

4

1 回答 1

0

我想我已经找到了答案。谷歌地图似乎考虑了他们所有的控制(即使它们被隐藏)。基于此,真正的可见区域更小。请检查以下线程:https ://groups.google.com/forum/?fromgroups#!topic/google-maps-js-api-v3/5kSPwZfDyJI

于 2013-05-17T11:38:39.533 回答