开发者

How to center map on marker and open marker's InfoWindow in one method

开发者 https://www.devze.com 2022-12-18 01:33 出处:网络
I\'m using Google Map APIv2. On my webpage I\'ve a sidebar containing a list of markers with onclick event executing showDetails method, that looks like:

I'm using Google Map APIv2. On my webpage I've a sidebar containing a list of markers with onclick event executing showDetails method, that looks like:

GMarker.prototype.showDetails=function() { map.panTo(this.getLatLng()); this.openInfoWindowHtml(this.details); };

The problem is that i cannot both panTo and openInfoWindowHtml in one method, it pans but won't open tooltip and when i change method to:

GMark开发者_开发百科er.prototype.showDetails=function() { this.openInfoWindowHtml(this.details); map.panTo(this.getLatLng()); }; it opens tooltip but won't center map to the marker's anchor coordinates. Even using wait function doesn't solve my problem. What am I doing wrong?


You need to first do an addListener to wait until the map is done moving with the 'moveend' event. Then in your event handler call removeListener on the listener that you created so that the event handler only runs once. After that in the event handler open your info window.


the openInfoWindowHtml method should trigger a panto to put the infowindow in the viewport

ie

marker is outside the viewport and you trigger the infowindow on that marker - the map should pan to that location +/- so that the infowindow is centered in the viewport

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号