我正在研究谷歌地图我试图将标记添加到谷歌地图然后尝试删除它但现在我已经完成了添加和删除下面的代码
<html> <head> <Meta name="viewport" content="initial-scale=1.0,user-scalable=no"> <Meta charset="utf-8"> <title>MapsApi</title> <style> #map_canvas { width: 100%; height: 500px; background-color: #CCC; } #menu_bar{ width: 100%; height: 150px; position:absolute; bottom:0px; background-color: #CCC; border-top:1px solid red; } body{ padding:0px; margin:0px; } </style> <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var map; var markers = []; function initialize() { var myLatlng = new google.maps.LatLng(44.5403,-78.5463); var mapOptions = { zoom: 4,center: myLatlng } var map = new google.maps.Map(document.getElementById('map_canvas'),mapOptions); google.maps.event.addListener(map,'click',function(event) { addMarker(event.latLng); }); // add marker to positon function addMarker(location) { var marker = new google.maps.Marker({ position: location,map: map }); google.maps.event.addListener(marker,function(event) { this.setMap(null); }); markers.push(marker); } // Sets the map on all markers in the array. function setAllMap(map) { for (var i = 0; i < markers.length; i++) { markers[i].setMap(map); } } } google.maps.event.addDomListener(window,'load',initialize); </script> </head> <body> <div id="map_canvas"></div> <div id="menu_bar"> </div> </body> </html>
但现在这里有一个问题我应该如何设置markers.push(marker)的值,因为我已经删除了一个标记,因此它的值必须小于其预期存储的..可以任何一个帮助