A
A
Alex2015-01-21 19:54:05
Google Maps
Alex, 2015-01-21 19:54:05

Google maps - how to build a logical, short route?

Actually there are points.
A - start
D - end
The route is built according to the sequence of points in the array. (a,b,c,d)
Is it possible to somehow make the route more logical from a human point of view?
Those. we start our let at point A, the next point is B, but it would be shorter and probably more logical to look at point D and then B.
Maybe there is a built-in mechanism or a ready-made calculus algorithm?
98176e31753e4f6ea7852c3d282216cb.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergeyj, 2015-01-22
@sensus

You need to calculate the farthest point from the starting point.
This far point will be the end point, the remaining points will be built automatically.

var waypoints = [
      "40.7513888888889,-73.9777777777778",
      "40.7083333333333,-74.0141666666667",
      "40.7752777777778,-73.9769444444444",
      "40.7252222222222,-73.9993888888889",
      "40.7652777777778,-73.9791666666667"
    ];
var andrLT = []; 
var andrLN = []; 
var Ri;
for (i = 0; i < waypoints.length; i++) {
      andrLT.push(parseFloat(waypoints[i].split(',')[0]));
      andrLN.push(parseFloat(waypoints[i].split(',')[1]));
}

for (i = 0; i < waypoints.length; i++) {
      sqrt = Math.sqrt(((40.7791666666667 - andrLT[i])*2 + (73.9583333333333 - andrLT[i])*2)+300);
      Ri.push([ sqrt ]);
}

// Узнаем максимальное значение массива точек
console.log(Math.max.apply(Math, Ri));

You got a far point, then you get the coordinates with the conditions and already implement the mechanism.

D
Dmitry Entelis, 2015-01-21
@DmitriyEntelis

math.semestr.ru/kom/kom_practice.php
https://www.lektorium.tv/lecture/14235

A
Avivar, 2015-01-21
@Avivar

Check out google maps api https://developers.google.com/maps/customize?hl=en
API allows you to create the best route options. If you implement the drag and drop function, users will be able to independently lay routes directly on the map. Route optimization organizes up to 25 waypoints to reduce travel time and distance. Using the Distance Matrix API gives users the ability to view distance data to destinations and travel time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question