Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps Api: set center of the map to an offset in pixels?

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?

like image 328
matt Avatar asked Jan 17 '13 10:01

matt


People also ask

How do I center a Google map?

Please go to your map and drag and drop your map to the position you wish. You can also zoom in your map a little bit with mouse wheel or zoom cotrols on the bottom right corner of the map. Please remember to save your map after any changes. Hope that helps.

Can you customize Google Maps API?

Create a map with the Google Maps API.Google Maps Platform gives you the ability to create a truly custom map that works exactly how you want it to. This method has the advantage of being the most flexible and is free up to certain limits set by Google.

How do you change the InfoWindow position on Google Maps?

An InfoWindow can be placed on a map at a particular position or above a marker, depending on what is specified in the options. Unless auto-pan is disabled, an InfoWindow will pan the map to make itself visible when it is opened. After constructing an InfoWindow, you must call open to display it on the map.


1 Answers

call the panBy-method of the map

mapObject.panBy(0,30)
like image 71
Dr.Molle Avatar answered Sep 23 '22 14:09

Dr.Molle