I'm using maps api in my app and when i what to see the created route i have the choice of set optimizeWaypoints = true to organize the waypoints but... I need to see that route on google maps page, but whenever i try that the way points are not "optimized".
I have done this that way:
for (var i = 0; i < wayptss.length; i++) {string_de_waypoints += wayptss[i] + '/';} var addresses = string_de_waypoints;
var address2 = document.getElementById("end").value;
// window.open("https://maps.google.ch/maps?saddr=["+address1+"]&daddr=["+address2+"] to:["+address3+"] to: ["+address4+"]to: ["+address5+"]")
link_maps = "https://www.google.ch/maps/dir/"+address1+"/"+addresses+address2;
window.open(link_maps)
The value come from here:
const waypts = [];
const checkboxArray = document.getElementById("waypoints");
wayptss=[];
for (let i = 0; i < checkboxArray.length; i++) {
if (checkboxArray.options[i].selected) {
waypts.push({
location: checkboxArray[i].value,
stopover: true,
});
//-----------------HERE--------------------------------
wayptss.push(checkboxArray[i].value,
);
}
Well... What i want to know is, if I have some way to do that like exporting directly the route to google maps or something like that. Or if not at least a way to optimize the route waypoints array by getting his distance or something like that.
Ok i found a solution. I used this:
summaryPanel.innerHTML += route.legs[i].start_address + " to ";
summaryPanel.innerHTML += route.legs[i].end_address + "<br>";
summaryPanel.innerHTML += route.legs[i].distance.text + "<br><br>";
https://developers.google.com/maps/documentation/javascript/directions