I have a map created using the Google Maps API, and I'd like to restrict panning to one globe; by default you can pan continuously east/west, the map repeats endlessly. I'm trying to use henningj's solution posted 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);
});
What I have currently allows no panning whatsoever, the call to 'contains' always fails. If I log map.getCenter() it all looks sensible enough, I think(?!):
Object { A: 54.683366, F: 25.31663500000002 }
Can anyone see what I'm doing wrong?