我想要实现的(到目前为止找不到任何东西)是 infoWindow 没有附加到标记。我想将其放置在视口中的静态位置,并根据单击的标记交换内容。
问:如何将谷歌地图标记信息窗口放置(而不仅仅是偏移)到固定位置。
回答我自己的问题 - 如果有人需要这个:
// Add somewhere before creating your map to hide the info window as long as it got no content:
<script type="text/javascript">
jQuery( '#info' ).hide();
</script>
<script type="text/javascript">
function createMarker( lat, lng, whatever ) {
// map_object_name = the name of your map when you init()
html = "<strong>" + whatever + "</strong>";
var marker = new google.maps.Marker( {
map: map_object_name,
position: new google.maps.LatLng( lat, lng )
} );
// This snippet adds the content on the fly (when you click the marker)
google.maps.event.addListener( marker, 'click', function() {
// This pans the viewport/centers the marker in your viewport
map_object_name.panTo( new google.maps.LatLng( lat, lng ) );
// This shows the html-element with the id "info" and adds the html content
jQuery( '#info' ).show();
// This clears the content before you add new one
jQuery( '#info' ).empty();
jQuery( '#info' ).append( html );
// Commented out - just as reference
// infoWindow.setContent( html ); // the original infoWindow as you know it from Google Maps
// infoWindow.open( map_object_name, marker ); // the same, just the callback
} );
}
</script>
“放置”/定位#info
元素可以用普通的 html 和 css 来完成。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)