N
N
Nodir Malikov2020-05-07 09:51:40
Python
Nodir Malikov, 2020-05-07 09:51:40

How to calculate the nearest points in Python using the available GPS coordinates?

I'm making a telegram bot that looks for the nearest restaurants, the coordinates of which I have in the dictionary, after receiving a geolocation from the user. I can't find any examples or answers to this on the internet. And it's not on the docks. Who can give an example and suggest how to do this?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
N
Nodir Malikov, 2020-05-07
@Fayo

Everything turned out to be simple) geopy helped me

V
Vladimir, 2020-05-07
@vintello

it's practically impossible . I don't think anyone has ever solved this problem . I don't even know what to suggest

S
Sergey Pankov, 2020-05-07
@trapwalker

searches for the nearest restaurants, the coordinates of which I have in the dictionary

If your bot plans to grow and support many different POIs, including in addition to restaurants, then it makes sense to put all this in the database.
It is convenient to use postgres with the postgis extension. As part of this extension, there are optimized functions for finding the nearest points, in addition, it is convenient to store the POIs themselves in the database, they can be imported from OSM.
In addition, not in all such problems it is correct to use geometric metrics to find the nearest points.
Some point may be closer to the given geometrically, but it may be on the other side of the river, and the detour across the bridge to it will be very large.
To do this, you'd better use some solution that takes into account routing. For example OSRM. Such services are often able to build matrices of distances between points. OSRM, by the way, is perfectly deployed in the docker, based on OSM data, it can build both walking routes (if, of course, your region is covered with hiking trails in OSM), and in other modalities.
A useful artifact from OSRM would also be the geometry of the route and the waypoints along the route. OSRM also has a fast method in its API to dynamically bind coordinates to a road graph. It can be useful, say, to track the courier and warn of his arrival.

V
Vladimir Korotenko, 2020-05-07
@firedragon

as one of the options.
https://pypi.org/project/geolocation-python/
Also if you need distance stupidly
try this
https://stackoverflow.com/questions/365826/calcula...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question