надеюсь, что этот код решит вашу проблему
var directionsService = new google.maps.DirectionsService ();var directionsDisplay = new google.maps.DirectionsRenderer ({map: map, preserveViewport: true});// console.log ("Lastdata:", lastdata);// console.log ("perulangan maksimal:", perulanganmaksimal);waypts = [];for (var x = 1; x
directionsService.route({
origin: new google.maps.LatLng(obj[0].lnglat_pecah[0], obj[0].lnglat_pecah[1]),
destination: new google.maps.LatLng(lastdata.lnglat_pecah[0], lastdata.lnglat_pecah[1]),
waypoints: waypts,
travelMode: google.maps.TravelMode.DRIVING
}, function(response, status) {
if (status === google.maps.DirectionsStatus.OK) {
symbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
// path : 'M 10,30 A 20,20 0,0,1 50,30 A 20,20 0,0,1 90,30 Q 90,60 50,90 Q 10,60 10,30 z',
scale: 3,
strokeColor: '#F00'
};
polyline = new google.maps.Polyline({
path: [],
strokeColor: '#0000FF',
strokeWeight: 3,
geodesic: geodesicvalue,
icons: [{
icon: symbol,
offset: '100%',
repeat: repeated
}]
});
var bounds = new google.maps.LatLngBounds();
// console.log("polyline", polyline);
var legs = response.routes[0].legs;
// console.log("legs", legs);
for (ulang = 0; ulang < legs.length; ulang++) {
var steps = legs[ulang].steps;
for (j = 0; j < steps.length; j++) {
var nextSegment = steps[j].path;
for (k = 0; k < nextSegment.length; k++) {
polyline.getPath().push(nextSegment[k]);
bounds.extend(nextSegment[k]);
}
}
}
polyline.setMap(map);