gmaps with bounds
HTML
<script src="http://maps.google.com/maps/api/js?sensor=true&.js"></script>
<div id="map"></div>
CSS
html,
body,
#map {
display: block;
width: 100%;
height: 100%;
}
#map {
background: #58B;
}
JavaScript
var myOptions = {
center: new google.maps.LatLng(47.259998, 11.398032),
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(47.260071, 11.404705),
map: map,
title: 'Hello World!'
});
// Replace this with call to $("#arrow").offset()
var arrowPos = { top: 50, left: 100 };
var getPixelOffset = function(map, marker) {
// Calculate marker position in pixels form upper left corner
var scale = Math.pow(2, map.getZoom());
var nw = new google.maps.LatLng(
map.getBounds().getNorthEast().lat(),
map.getBounds().getSouthWest().lng()
);
var worldCoordinateNW = map.getProjection().fromLatLngToPoint(nw);
var worldCoordinate = map.getProjection().fromLatLngToPoint(marker.getPosition());
var pixelOffset = new google.maps.Point(
Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale),
Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale)
);
return pixelOffset;
};
// Wait until the map is initialized
var listener = google.maps.event.addListener(map, "idle", function() {
var pixelOffset = getPixelOffset(map, marker);
// Do the pan
map.panBy(Math.abs(pixelOffset.x - arrowPos.left),
Math.abs(pixelOffset.y - arrowPos.top));
google.maps.event.removeListener(listener);
if (bounds.getNorthEast().equals(bounds.getSouthWest())) {
var extendPoint = new google.maps.LatLng(bounds.getNorthEast().lat() + 0.01, bounds.getNorthEast().lng() + 0.01);
bounds.extend(extendPoint);
}
});