I am trying to use this function found online to calculate the distance between two latitude and longitude points on the Earth.
However, I do not know how to pass my values for latitude and longitude because I replace lat1, lon1 and lat2, lon2, and I get an error every time.
Where do i put in the values I want for latitude and longitude?
import math
def distance(origin, destination):
lat1, lon1 = origin
lat2, lon2 = destination
radius = 6371 # km
dlat = math.radians(lat2-lat1)
dlon = math.radians(lon2-lon1)
a = math.sin(dlat/2) * math.sin(dlat/2) + math.cos(math.radians(lat1)) \
* math.cos(math.radians(lat2)) * math.sin(dlon/2) * math.sin(dlon/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = radius * c
return d
EDIT: For example, if I have
lat1 = 20 and lon1 = 100
lat2 = 30 and lon2 = 110
why does it fail when I replace lon1 with the number in the function?