4
我想实现的目标(到目前为止找不到任何东西)是infoWindow未附加到标记。我想将它放置在视口中的静态位置,并根据点击的标记交换内容。将信息窗口放置在远离标记的静态位置(Google Maps)
问:如何将Google地图标记infowindow放置在一个固定位置(而不仅仅是偏移)。
我想实现的目标(到目前为止找不到任何东西)是infoWindow未附加到标记。我想将它放置在视口中的静态位置,并根据点击的标记交换内容。将信息窗口放置在远离标记的静态位置(Google Maps)
问:如何将Google地图标记infowindow放置在一个固定位置(而不仅仅是偏移)。
回答我的Q - 万一有人需要这样的:
// 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 &来完成。
问题。您的自定义infowindow是在地图上还是在地图上?谢谢! – Seano666
@ Seano666问题是2 1/2岁,但从查看代码,我会说'#info' DOM元素在地图之外,但注释掉的infoWindow应该在地图上 - 你我仍然需要创造它。嗯。你可以将'#map'容器设置为'position:relative; z-index:1;'和'#info'元素为'position:absolute;顶部:XYpx;左/右:XYpx; z-index:10;'将其置于地图上方的静态位置。 – kaiser