Home javascript How to calculate the distance from one address to another

How to calculate the distance from one address to another

Author

Date

Category

Customer wants to do on the site Calculator View:  Enter here a description of the image

You choose the city, enter 2 addresses and calculator counts kilometer. How can this be implemented? And in general, is it really?


Answer 1

If the customer is ready to display the data on the map, then you can get the address using the Sage https: //Tech.yandex.ru/maps/jsbox/2.1/suggest , build a route on the map using an example https://tech.yandex.ru/maps/jsbox/2.1/multiroute_Data_Access and get the length of the route.

If without a card, then the second item is changing on an HTTP request, which you can read here: https://tech.yandex.ru/routing/router/?from=mapsapi


Answer 2

In general, really. Probably the interface will still differ, since both Yandex Maps and Google Maps require addressing addresses along with the city.

You will need a geocoding API, for example Google Geocoding API . You send a request containing the address and the service returns you to the coordinates.

Then, with, for example, Gaversinus Formulas You calculate the distance between two points specified by your coordinates.

In this case, we are talking about calculating the smallest distance, that is, the lengths of the arc connecting two points. If we are talking about building a route, here you will help Direction API . Google or Yandex can build several routes immediately, their length can be different.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions