Answer the question
In order to leave comments, you need to log in
Displaying goods on the site sorted by distance from the address of the buyer?
Hello.
There was a need to display the goods on the site by sorting them by distance from the address of the buyer.
I get the buyer's delivery address from the database ( Blagoveshchensk, Lenina street, building 1 ), now I need to display the goods ( which also have a warehouse address ) sorting them by distance from the buyer's address.
Example:
the address of the buyer is Lenin street 1, then the goods should be displayed in the order:
1) product (with the address Lenin street 2)
2) product (with the address Lenin street 10)
3) product (with the address Lenin street 24)
4) product ( with the address Kirova street 140/2 to 1)
5) goods (with the address Komsomolskaya street 12A)
.....
Is it really possible to implement this? If yes, please help with advice.
Yandex Maps API is connected to the site.
Answer the question
In order to leave comments, you need to log in
Option 1:
We read the data using the Distance Matrix, stupidly feeding it two addresses: https://yandex.com/dev/routing/distance_matrix/
Option 2:
1. We drive into the system in addition to the warehouse address, its latitude and longitude
2. Find out the latitude and the longitude of the user when entering the address (yandex autocomplete can do this, although for address hints in the Russian Federation I would choose Dadata, because it recognizes user input much better. Well, you can get latitude and longitude here and there)
3. Calculate the distance , knowing latitude and longitude of two objects
The first option is simpler, but it may be more expensive, especially if you have a lot of orders.
Option 3:
Build isochrones for warehouses. Then it remains to find the "fastest" zone - that's our nearest warehouse.
store the latitude/longitude of cities, sort by the distance between the city of the warehouse and the city of the client
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question