Google-maps – Google Maps Api: set center of the map to an offset in pixels

google mapsgoogle-maps-api-3

this might be a weird question …

I'm using the google maps api to embed custom maps on my webpage. I pass the lon/lat coordinates along to a function and a map is drawn with this point "centered" in the middle. (my map frame is like 300px high, so the marker is approx at 150px)

Since I'm also using custom infoWindows/Boxes I'd like to move the center of the map a bit down.

I know I could set a seperate center in lon/lat coordinates but that's not what I'm looking for. This would require for every map to pass along the coordinates of the marker and the coordinates of the center I'd like to have.

I'd like it to be more simple.

Is it possible to move the center of the map just a few pixels down?

Like center: +30px, 🙂

var latlng = new google.maps.LatLng(ll[0], ll[1]); // latitude and longitude
    var options = {
    zoom: zoom,
    //center: c,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    mapTypeControl: false,
    disableDefaultUI: true,
    scrollwheel: scroll,
    streetViewControl: false,
    navigationControlOptions: {  
        style: google.maps.NavigationControlStyle.SMALL 
    }
}

Any idea how I could do that? Any oder tricks or ideas?

Best Answer

call the panBy-method of the map

mapObject.panBy(0,30)