0

我想在地图上显示标记。这些必须移动一个新的位置。

由于我无法确定移动标记,我决定删除现有标记并创建一个新标记。

但标记不会被删除。相反,具有相同标签的新标记会不断出现在新位置。

  var markers = [];     


function addMarker(lat, lon, id, label, speed, course, temp) {

    var marker = new MarkerWithLabel({
        name:id,
        id:id,
        position: new google.maps.LatLng(lat, lon),     
        draggable: true,
        optimized:false,
        map: map,
        labelContent: label,
        labelAnchor: new google.maps.Point(22, 0),
        labelClass: "labels",  
        labelStyle: {opacity: 0.75}
    });

    if(temp!=""){
        temptext = "<br />Temprature "+ temp;
    }  else{
        temptext =" ";
    }



    markers[id]=marker;
    console.log(markers);
    iw[id] = new google.maps.InfoWindow({
        content: "<b>"+label+"</b><br />Speed:"+speed+" KM/h "+ "<br />heading "+ course + temptext+"<br />["+id+"]",       
    });
    google.maps.event.addListener(marker, "click", function (e) { iw[id]
        .open(map, marker); });

}


   function clearMarker(id){

    if(typeof markers[id] == 'object'){

        console.log("key exists" +id);  
        delmarker = markers[id]
        delmarker.setMap(null);
         parent.markers.splice(id, 1)  ;
         //console.log(markers);     
    }      else{
        console.log(id+ "key does not exist" );      
    }

}
4

0 回答 0