Given a list of tuples containing coordinates, I want to find which coordinate is the closest to a coordinate I give in input:
cooList = [(11.6702634, 72.313323), (31.67342698, 78.465323)]
coordinate = (11.6702698, 78.113323)
takenearest(myList, myNumber)
...
(11.6702634, 72.313323)
Please let me know...
If I understand you right, you want the coordinate from the list that has the least distance to the given coordinate. That means you can just loop through the list like that:
To calculate the distance between two variables, just use Pythagoras.
I hope this helps!
For your data
the shortest Pythonic answer is:
with a function
distance(a, b)
returning the distance between the pointsa
andb
as a float, which you have to define yourself.Now you have to decide how you calculate the distance: using simple
a² + b² = c²
, some geographical formula or a dedicated library.