有一个字典a
a = {0: (-37.4168610028693, 145.005372256037),
1: (-37.7032933463858, 144.572524145218),
2: (-37.7292612709136, 144.650631483984),
3: (-37.7777637471456, 144.772303608804),
4: (-37.5792063872414, 144.72816450831)}
我想写一个函数来计算某个点到a字典中所有点的haversine距离并且返回最短距离和字典的key,我的代码如下:
def get_min_dis2(a:dict,b:tuple):
min_dist = 10000
for k in a.keys():
lat1, lon1 = a[k]
lat2, lon2 = b
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))
distance = c * 6378
if distance < min_dist:
min_dist = distance
key = k
return (key,b,min_dist)
get_min_dis2(a,(-37.8438,145.0303))
但是我运行时会一直报错TypeError: 'float' object is not subscriptable
请问要如何解决呢