I have the following JSFiddle (originally from this thread: Google Maps v3 - limit viewable area and zoom level) which presents the user with a fixed area of Google Maps: http://jsfiddle.net/9f3f82vw/4/
// This is the minimum zoom level that we'll allow
var minZoomLevel = 14;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: minZoomLevel,
center: new google.maps.LatLng(53.2170249, 6.5656727),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: {lat: 53.218573, lng: 6.567293},
map: map,
title: '???'
});
// Bounds for Groningen
var strictBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(53.2124505, 6.5558022), //Southwest
new google.maps.LatLng(53.2212904, 6.5760153)); //Northeast
// Listen for the dragend event
google.maps.event.addListener(map, 'bounds_changed', function () {
if (strictBounds.contains(map.getCenter())) return;
// We're out of bounds - Move the map back within the bounds
var c = map.getCenter(),
x = c.lng(),
y = c.lat(),
maxX = strictBounds.getNorthEast().lng(),
maxY = strictBounds.getNorthEast().lat(),
minX = strictBounds.getSouthWest().lng(),
minY = strictBounds.getSouthWest().lat();
if (x < minX) x = minX;
if (x > maxX) x = maxX;
if (y < minY) y = minY;
if (y > maxY) y = maxY;
map.setCenter(new google.maps.LatLng(y, x));
});
// Limit the zoom level
google.maps.event.addListener(map, 'zoom_changed', function () {
if (map.getZoom() < minZoomLevel) map.setZoom(minZoomLevel);
});
The problem with this solution is that once you zoom in, you can't get near the areas close to the bounds. So, if you go to the south of the map with the original zoom (14) and you zoom in, you'll notice that you'll not be able to go completely south.
In other words, you can't zoom in on the border.
EDIT: I've dropped the whole border thing and implemented a fog layer to let the user know that there's an area that he can't access. I did this with the help of http://maps.vasile.ch/geomask/
Thnx!