我已经使用地图 API 计算了具有相同起点和终点的路线。
由于起点和终点相同,因此第一个标记与最后一个标记重叠。现在我只想删除最后一个标记。
我只知道如何隐藏它们:
directionsDisplay.suppressMarkers = true;
有没有办法循环遍历标记并删除最后一个?
这是我用于指示的代码:
function calcRoute(waypts) {
var start = waypts[0].location;
var end = waypts[0].location;
var request = {
origin:start,
destination:end,
waypoints:waypts,
optimizeWaypoints: true,
provideRouteAlternatives:false,
travelMode:google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.suppressInfoWindows = true;
directionsDisplay.suppressMarkers = true;
directionsDisplay.setDirections(response);
console.log(status);
}else{
alert('SATUS:'+response.status);
}
});
}
尝试这个
初始化中
directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true});
then
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var route = response.routes[0];
var start =route.legs[0].start_location;
var end =route.legs[0].end_location;
addMarker(end);
添加标记函数
function addMarker(pos){
var marker = new google.maps.Marker({
position: pos,
map: map,
icon: 'images/your image'
}
)
}
我还没有测试过这个,但你应该明白
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)