I am calculating the nearest distance of two points (latitude, longitude). My code is as below:
R = 6378.0
distsecKM = []
for i in range(len(pLat)):
lat1 = math.radians(pLat[i])
lon1 = math.radians(pLon[i])
temp = []
for j in range(len(secondaryLat)):
lat2 = math.radians(secondaryLat[j])
lon2 = math.radians(secondaryLon[j])
diffLat = lat2 - lat1
diffLon = lon2 - lon1
a = ((math.sin(diffLat / 2))**2) + (math.cos(lat2)) * (math.cos(lat1)) * ((math.sin(diffLon / 2))**2)
b = 2 * math.atan2(sqrt(a), sqrt(1 - a))
dist = R * b
temp.append(dist)
distsecKM.append(min(temp))
I am getting the smallest distance between point1(lat1,lon1) and point2(lat2,lon2). However, I also want to get the lat2 and lon2 used to calculate the smallest distance and save it to a list perhaps.
How do I go about this?