J
J
Jazz75RUS2016-08-12 12:00:23
JavaScript
Jazz75RUS, 2016-08-12 12:00:23

How can you calculate and display the distance to a point on the map?

Good, there is an example on the site restoran.ru
where distances to establishments are displayed, are there ready-made solutions for such an implementation, if not dynamic (from the current location), then at least from a certain, predetermined point? The coordinates of the points are available through Yandex api, you need to calculate the distance to them .. Thank you

Answer the question

In order to leave comments, you need to log in

4 answer(s)
O
OVK2015, 2016-08-12
@Jazz75RUS

If without API, only by coordinates, there is a library
https://github.com/turfjs

D
Dmitry Belyaev, 2016-08-12
@bingo347

Give you all a ready-made lib for every sneeze ...
We read the theory here: https://ru.wikipedia.org/wiki/%D0%A2%D0%B5%D0%BE%D...

function distantion(x1, y1, x2, y2) {
  return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
}

D
DarthKitsune, 2016-08-12
@DarthKitsune

What exactly do you need - the distance between two points on the map (which is a straight line and passes through yards / gardens / houses / other), or an adequate distance on the roads?
If the former, then Dmitry Belyaev gave the correct answer.
If the latter, you need to build a weighted digraph and look for paths from one vertex to another on it. More details (theory, algorithms, without reference to practice) - in this article https://habrahabr.ru/post/119158/

V
Vladislav, 2016-08-14
@vlad00777

Google distance matrix for example: https://developers.google.com/maps/documentation/d...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question