我已尝试在此处查看各种代码块以及Google Maps API文档,但STILL尚无法弄清楚如何隐藏标记.
这是我正在使用的当前代码,它适用于一个实例.一旦我在带有markers.setMap(null)的函数中添加了"for"循环,Firefox就会显示以下错误:
错误:TypeError:markers.setMap不是函数
function removeMarkers(){
var markers;
alert(markers);
alert(locations.length);
for (i = 0; i<locations.length; i++){
markers = locations[i];
alert(markers.title);
markers.setMap(null);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用Google Maps API创建具有给定点的方向.
我需要将点数命名为1,2,3 ... 99(已完成).
这些点也必须是可拖动的.
但是当我使得点可拖动时,方向不会自行刷新,点的位置会改变但不会改变方向,
以下是示例代码(取自 - > Google Maps Directions,使用1-2-3代替ABC);
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("maps", "3",{other_params:"sensor=false"});
function init(){
directionsService = new google.maps.DirectionsService();
var pos = new google.maps.LatLng(41.218624, -73.748358);
var myOptions = {
zoom: 15,
center: pos,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map'), myOptions);
directionsDisplay = new google.maps.DirectionsRenderer({map: map, suppressMarkers: true,draggable:true});
directionsService.route({
origin: "New York",
destination: "Chicago",
waypoints: [{location:"Philadelphia"}, {location:"Boston"}], //other duration points
optimizeWaypoints: true,
travelMode: google.maps.TravelMode.DRIVING
}, function(response, status) {
if (status === …Run Code Online (Sandbox Code Playgroud)