我可以尝试使用我的地图复选框进行控制。我搜索所有网站,并尝试了两天后的不同方式,我不能。
<div class="xx" onclick="x();"></div>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCA2WMMIAgJiHsnxIsO3mJC3F5vLINgAW&sensor=false"></script>
<script type="text/javascript">
var markers = [{"title":'Kaya',"lat":'40.8309889',"lng":'39.460643',"icon":'gmi6.png'},...];
window.onload = function () {LoadMap();}
function LoadMap() {
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
var styleArray=[.....
var mapOptions={center: new google.maps.LatLng(40.818575, 39.685296),zoom:10,minZoom: 9,styles: styleArray,mapTypeId: google.maps.MapTypeId.ROADMAP};
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
var infoWindow = new google.maps.InfoWindow();
for (var i = 0; i < markers.length; i++) {
var data = markers[i];
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map:map,
icon:iconBase + data.icon,
title: data.title.replace("'", "´")});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent("<div style='width:250px;min-height:40px;'><a href='" + data.urllink+"'><h4>"+data.title +"</h4><br><img alt='' src='"+ data.image +"' style='width:100%;'></a>"+ data.description + "</div>");
infoWindow.open(map, marker);
});
})(marker, data);
}
}
function x() {
for (var i = 0; i < markers.length; i++) {
markers[i].setVisible(false);
}
}
</script>
<div id="dvMap" style=".."></div>
console log:markers.lenght:40 ok。 , markers [i]:[object object]。我不明白。
就像我犯了一个错误,但在哪里或如何?
标记[i]无效或无法正常工作