Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
Needs more info comment that > 10 days [ID: 963198]
Comment such as: SPAM, non-actionable [ID: 963127]
Resolved actionable follow-up comments [ID: 963027]
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
Description
That means when we set optimizeWaypoints: true, first 3 waypoints cannot be change. they must kept their order and last 7 waypoints must change the order to optimize. Can we do it? or it is not working in DirectionsService?
I tried the following code to fixed some waypoints. but it not working.
var directionsService = new google.maps.DirectionsService();
var directionsRenderer = new google.maps.DirectionsRenderer();
function calculateRoute() {
directionsService.route(
{
origin: "Colombo, Sri Lanka", // Locked
destination: "Kandy, Sri Lanka", // Locked
travelMode: google.maps.TravelMode.DRIVING,
drivingOptions: {
departureTime: new Date(), // Real-time traffic
trafficModel: "best_guess",
},
waypoints: [
// 🚀 LOCKED waypoints (first 3, not optimized)
{ location: "Gampaha, Sri Lanka", stopover: true },
{ location: "Negombo, Sri Lanka", stopover: true },
{ location: "Minuwangoda, Sri Lanka", stopover: true },
// 🛠Optimized waypoints (remaining 7)
{ location: "Kurunegala, Sri Lanka", stopover: true },
{ location: "Dambulla, Sri Lanka", stopover: true },
{ location: "Matale, Sri Lanka", stopover: true },
{ location: "Mawanella, Sri Lanka", stopover: true },
{ location: "Pilimathalawa, Sri Lanka", stopover: true },
{ location: "Peradeniya, Sri Lanka", stopover: true },
{ location: "Kadugannawa, Sri Lanka", stopover: true },
],
optimizeWaypoints: true, // Optimizes the last 7 waypoints only
},
function (response, status) {
if (status === "OK") {
directionsRenderer.setDirections(response);
// Check the waypoint order in the response
var optimizedOrder = response.routes[0].waypoint_order;
console.log("Optimized waypoint order:", optimizedOrder);
// Check if the first 3 waypoints remain unchanged
console.log("First 3 waypoints should not be optimized:");
console.log("1. Gampaha -> Expected Position: 0");
console.log("2. Negombo -> Expected Position: 1");
console.log("3. Minuwangoda -> Expected Position: 2");
} else {
console.error("Directions request failed due to " + status);
}
}
);
}