I want to compute the distance (in km) using geopy library between two points defined by their respective (lat, lon) coordinates.
My code
from geopy.distance import great_circle
# lat, lon
p1 = (45.8864, -7.2305)
p2 = (46.2045, -7.2305)
# distance in km
great_circle(p1, p2).km
>>> 35.371156132664765
To check above results, I used the tool available here: https://www.movable-type.co.uk/scripts/latlong.html but the two outputs do not match.
The output of my code is 35.371156132664765
though the above tool returns a distance of 15.41 km.
How come the results are different ?
Your calculation for the points p1
and p2
is wrong, you need to convert the minutes and seconds into degree correctly. Otherwise the code works prefectly.