E
E
E6APB2017-08-17 22:20:42
PHP
E6APB, 2017-08-17 22:20:42

How to competently search for the nearest objects, taking into account routes?

Let's say I need to find the nearest couriers. For this I use the Haversine formula. Found. Everything is great. But there is a problem - for example, the closest courier according to the formula is across the river, but in fact the nearest courier is a little further from the search point. And the system will eventually choose a courier who is on the other side, he will need to reach the bridge, cross the river, etc. And the second courier turned out to be actually closer, because he did not need to cross the river. How is such a problem solved? I know that I will have to use the maps API, because I do not have these routes.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fortop, 2017-08-17
@E6APB

You have two options.
1. If you are large and can store a graph of all connections of the objects you need. Then just do it and calculate the routes and distances according to the graph. In this case, the distance along the graph for the shortest straight line across the river will naturally be greater.
2. If you are small, then consider the distances along the routes issued by the mapping API.
And take what you need.

F
freeExec, 2017-08-18
@freeExec

Or share couriers who work only on one or the other coast.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question