Refer to this question: How do I compensate for the center of the Google Maps (API v3) in pixels?
This is a modification of the answer I provided here .
google.maps.Map.prototype.setCenterWithOffset= function(latlng, offsetX, offsetY) { var map = this; var ov = new google.maps.OverlayView(); ov.onAdd = function() { var proj = this.getProjection(); var aPoint = proj.fromLatLngToContainerPixel(latlng); aPoint.x = aPoint.x+offsetX; aPoint.y = aPoint.y+offsetY; map.setCenter(proj.fromContainerPixelToLatLng(aPoint)); }; ov.draw = function() {}; ov.setMap(this); };
You can simply use it like this:
var latlng = new google.maps.LatLng(-34.397, 150.644); var map = new google.maps.Map(document.getElementById("map_canvas"), { zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP, center: latlng }); map.setCenterWithOffset(latlng, 0, 250);
Here is a working example .
Dean Or Sep 26 '12 at 19:06 2012-09-26 19:06
source share