Out of a list of given coordinates, I need to identify the latitude and longitude that are closest to a particular coordinate point.But I must also check that it is the right direction along the same line (with a certain maximum deviation of, say 10 degrees).
I have tried fooling around with the haversine distance formula, but I don't know how I can alter the code to find the closest coordinate at a certain angle instead of an sphere.
def dist(lat1, long1, lat2, long2):
# convert decimal degrees to radians
lat1, long1, lat2, long2 = map(radians, [lat1, long1, lat2, long2])
# haversine formula
dlon = long2 - long1
dlat = lat2 - lat1
a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
print(a)
c = 2 * asin(sqrt(a))
print(c)
# Radius of earth in kilometers is 6371
km = 6371 * c
return km
The code above is an example of haversine distance formula. Is there way to alter this code so that it disregards coordinates that are not at the right angle to the given point or should I look for something else (if so, do you guys have any ideas?)?