Google地图平移到灰色区域

时间:2018-08-06 13:53:28

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

所以我有一个Meteor应用程序,我正在使用dburles:google-maps来显示地图,但我无法使该地图不离开世界边界并平移到灰色区域,此处有一些提示,但似乎没有任何作用,这是我到目前为止的内容:

GoogleMaps.ready("map", async function (map) {
   google.maps.event.addListener(map.instance, 'center_changed', function() {
        checkBounds(map.instance);
    });

function checkBounds(mapIntance) {
  var latNorth = mapIntance.getBounds().getNorthEast().lat();
  var latSouth = mapIntance.getBounds().getSouthWest().lat();
  var newLat;

  if(latNorth < 85 && latSouth > -85)     /* in both side -> it's ok */
      return;
  else {
      if(latNorth > 85 && latSouth < -85)   /* out both side -> it's ok */
          return;
      else {
          if(latNorth > 85)
              newLat =  mapIntance.getCenter().lat() - (latNorth-85);   /* too north, centering */
          if(latSouth < -85)
              newLat =  mapIntance.getCenter().lat() - (latSouth+85);   /* too south, centering */
      };
  };
  if(newLat) {
      var newCenter = new google.maps.LatLng(newLat, mapInstance.getCenter().lng());
      mapInstance.setCenter(newCenter);
  };
};

并在模板中:

<input id="pac-input" class="controls" type="text" placeholder="Search places..." style="width:400px;">
      {{> googleMap name="map" options=mapOptions}}

此解决方案来自stackoverflow中的另一个答案。我需要帮助

0 个答案:

没有答案
相关问题