Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在谷歌地图API中将平移限制为一个地球_Javascript_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 在谷歌地图API中将平移限制为一个地球

Javascript 在谷歌地图API中将平移限制为一个地球,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我有一张使用谷歌地图API创建的地图,我想把平移限制在一个地球上;默认情况下,您可以连续向东/向西平移,贴图将无休止地重复。我正在尝试使用发布到的解决方案 我目前不允许任何平移,对“contains”的调用总是失败。如果我记录map.getCenter(),我想这一切看起来都很合理(?) 有人知道我做错了什么吗?您可以设置适当的缩放级别,并限制最小最大缩放级别 var mapOptions = { center: new google.maps.LatLng(50.4

我有一张使用谷歌地图API创建的地图,我想把平移限制在一个地球上;默认情况下,您可以连续向东/向西平移,贴图将无休止地重复。我正在尝试使用发布到的解决方案

我目前不允许任何平移,对“contains”的调用总是失败。如果我记录map.getCenter(),我想这一切看起来都很合理(?)


有人知道我做错了什么吗?

您可以设置适当的缩放级别,并限制最小最大缩放级别

      var mapOptions = {
        center: new google.maps.LatLng(50.431487, 30.539285),
        zoom: 2,
        minZoom: 2,
        maxZomm:19,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }

您的
允许边界定义不正确。它应该是(从):

LatLngBounds(sw?:LatLng,ne?:LatLng)从其西南角和东北角的点构造一个矩形

这:

应该是:

var allowedBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-85, -180),  //sw
    new google.maps.LatLng(85, 180)     //ne
); 
(负经度在正经度以西,负纬度在正经度以南)

      var mapOptions = {
        center: new google.maps.LatLng(50.431487, 30.539285),
        zoom: 2,
        minZoom: 2,
        maxZomm:19,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
var allowedBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(85, -180),
    new google.maps.LatLng(-85, 180)
);
var allowedBounds = new google.maps.LatLngBounds(
    new google.maps.LatLng(-85, -180),  //sw
    new google.maps.LatLng(85, 180)     //ne
);