我有以下代码:
<?php //include_once("connectionmarker.php");?>
<!DOCTYPE html >
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Cherrybird</title>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
(function() {
window.onload = function() {
// Creating a new map
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(50.8967,-1.40225),
zoom: 18,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var customIcons = {
Now: {
icon: 'img/fourmarker.png',
},
Soon: {
icon: 'img/marker.png',
}
};
// Creating a global infoWindow object that will be reused by all markers
var infoWindow = new google.maps.InfoWindow();
var list = document.getElementById('list');
$.getJSON("connectionmarker.php", function(data) {
for (var i = 0; i < data.length; i++ ){
// Looping through the JSON data
var datanew = data[i]
//alert (data[i].Availibility);
latLng = new google.maps.LatLng(datanew.Lat, datanew.Lon);
var iconimage = datanew.Availibility;
var icon = customIcons[iconimage] || {};
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: icon.icon,
title: datanew.Propertynanu
});
// add items
var listItem= document.createElement('li')
listItem.className = "content";
listItem.innerHTML = "House:" + datanew.Propertynanu + "<br />" + datanew.Postcode + "<br />" + datanew.Availibility + "<br />" ;
list.appendChild(listItem);
// Creating a closure to retain the correct data
(function(marker, datanew) {
// Attaching a click event to the current marker
google.maps.event.addListener(marker, "click", function(e) {
//"Id:" + data[i].Id + "<br /> Property Name/Number:" + data[i].Propertynanu + "<br /> Rooms:" + data[i].Rooms
infoWindow.setContent("House:" + datanew.Propertynanu + "<br />" + datanew.Postcode + "<br />" + datanew.Availibility + "<br />" );
infoWindow.open(map, marker);
});
})(marker, datanew);
}
});
}
})();
</script>
</head>
<body>
<div id="map" style="width: 1000px; height: 500px"></div>
<ul id="list"></ul>
</body>
</html>
我想要做的是将列表项动态添加到 div 中的页面,然后允许用户单击每个 div,相关 infoWindow 将显示在地图上。我已经使用 openlayers 完成了此操作,但现在需要使用 Google 地图完成此操作。
我已经将列表添加到页面,其中包含以下内容:
// add items
var listItem= document.createElement('div')
listItem.className = "content";
listItem.innerHTML = "House:" + datanew.Propertynanu + "<br />" + datanew.Postcode + "<br />" + datanew.Availibility + "<br />" ;
list.appendChild(listItem);
下一步是让它在列表中单击时显示相关标记的信息窗口。有人能帮忙吗。