我在地图上有 2 个标记。我想在发生某些事件时使这两个标记在地图上可见。但是当我restriction在地图上添加选项时fitBounds不显示标记。当我删除restriction选项时,它似乎工作正常。这是示例代码:
var map, markers;
var locations = [{
lat: 50.8503396,
lng: 4.351710300000036
},
{
lat: 49.9570366,
lng: 36.3431478
},
];
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 1,
center: {
lat: -28.024,
lng: 140.887
},
restriction: {
strictBounds: true,
latLngBounds: {
north: 85,
south: -85,
west: -180,
east: 180
},
},
});
markers = locations.map(function(location, i) {
return new google.maps.Marker({
position: location
});
});
markers.forEach(function(marker) {
marker.setMap(map);
});
}
setTimeout(function() …Run Code Online (Sandbox Code Playgroud)