简体   繁体   中英

Google Maps Offset Marker/Infowindow position (panTo/setCenter)

I'm in a bit of a pickle. I know this topic was already discussed, and solutions were presented, but none of them work for me. I'm working on a custom Google Map and need to have (quite large) infowindows displayed with markers. Currently the marker, when clicked, pans the map with the marker positioned in the center, so that the bottom of the infowindow meets the bottom of the map. I would like to have it pan to a specified distance (eg 100px) from the top of the map. Any help will be much appreciated :)
The code for the marker position is:

google.maps.event.addListener(marker1, 'click', function() {
infobox.open(map, this);
map.panTo(marker1.getPosition());

It may not be the most elegant solution, but adding another line below seems to do the trick, like so:

google.maps.event.addListener(marker1, 'click', function() {
infobox.open(map, this);
map.panTo(marker1.getPosition());
map.panBy(0, -425);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM