programming-examples/python/Math/Distance between two points using latitude and longitude.py

10 lines
441 B
Python
Raw Normal View History

2019-11-15 12:59:38 +01:00
from math import radians, sin, cos, acos
print("Input coordinates of two points:")
slat = radians(float(input("Starting latitude: ")))
slon = radians(float(input("Ending longitude: ")))
elat = radians(float(input("Starting latitude: ")))
elon = radians(float(input("Ending longitude: ")))
dist = 6371.01 * acos(sin(slat)*sin(elat) + cos(slat)*cos(elat)*cos(slon - elon))
print("The distance is %.2fkm." % dist)