0
我有一個谷歌地圖腳本,允許我在地圖上顯示帶有infowindows的標記。我的關注是:谷歌地圖,顯示載入信息窗口和addListener
a)如何打開和設置每個infoWindow ONLOAD的內容,所有的infoWindows彈出?
b)我怎樣才能讓jQuery「聽」到標記的infoWindow的內容?我的a-Tag裏面有一個類「show」,我有一個簡單的document.ready $('。show')。click(function()),它在窗口內點擊a-tag時什麼也不做。 Gmaps之外,它工作正常。
希望能幫到你,下面的腳本使用:
<script type="text/javascript">
var infowindow = null;
$(document).ready(function() {
initialize();
});
function initialize() {
var centerMap = new google.maps.LatLng(38, 10);
var myOptions = {
zoom: 5,
center: centerMap,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("gmap"), myOptions);
setMarkers(map, sites);
infowindow = new google.maps.InfoWindow({
content: "loading..."
});
var bikeLayer = new google.maps.BicyclingLayer();
bikeLayer.setMap(map);
}
var sites = [
['Test', 38, 10, 1, '<a href="#" class="show" data-popup="1"><img class="marker_class" src="91ccd318ae8b607500f54e7c56b5350e.png" alt="Preview"></a>']
];
function setMarkers(map, markers) {
for (var i = 0; i < markers.length; i++) {
var sites = markers[i];
var siteLatLng = new google.maps.LatLng(sites[1], sites[2]);
var marker = new google.maps.Marker({
position: siteLatLng,
map: map,
title: sites[0],
zIndex: sites[3],
html: sites[4]
});
var contentString = "Google Maps";
google.maps.event.addListener(marker, "click", function() {
infowindow.setContent(this.html);
infowindow.open(map, this);
});
}
}
</script>
<div id="gmap" class="map"></div>