2012-03-09 2 views
3

との最後の方向マーカを隠します。私はマップのAPIと同じ始まりと終点のルートを計算したGoogle Maps APIを

開始と終了点が同じであるため、第一マーカーは、最後のマーカーによって重なっています。今度は最後のマーカーだけを削除します。方法は、マーカーをループにあります

directionsDisplay.suppressMarkers = true; 

と最後の1を削除します。

私だけでそれらをすべて非表示にする方法を知っていますか?

これは私が指示に使用するコードです:

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); 

    } 
}); 
} 

答えて

4

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); 
その後、初期化

directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers: true}); 

でこの

を試してみてくださいaddMarker機能

function addMarker(pos){ 
var marker = new google.maps.Marker({ 
    position: pos, 
    map: map, 
    icon: 'images/your image' 

} 
) 
} 

は、私はこれをテストしていませんが、あなたのアイデアを得る必要があります

関連する問題