I need help with restricting panning on a Google Maps API map to just one globe. By default, the map allows continuous panning east/west, causing it to repeat endlessly. I found a solution by henningj in response to this question
var allowedBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(85, -180),
new google.maps.LatLng(-85, 180)
);
lastValidCenter = map.getCenter();
google.maps.event.addListener(map, "center_changed", function() {
if (allowedBounds.contains(map.getCenter())) {
lastValidCenter = map.getCenter();
return;
}
map.panTo(lastValidCenter);
});
The current setup is not allowing any panning at all, as the 'contains' function always fails. When I log map.getCenter(), the values seem correct:
Object { A: 54.683366, F: 25.31663500000002 }
Can anyone point out what mistake I might be making?