13
votes

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?

1
The answer to this question might help: stackoverflow.com/questions/2488999/…Marcelo
Well, in my case the window is already visible on page-load. I don't have to click the marker so autoPan doesn't really affect my problem.matt
autoPan refers to the map being panned to accommodate the infoWindow when it opens, so it should make no difference if the marker is already visible. It is easy however to shift the center by a few pixels, but I don't have the time right now. I'll post a piece of code later, if the question is still unsolved.Marcelo

1 Answers

29
votes

call the panBy-method of the map

mapObject.panBy(0,30)