我正在使用python及其第三方库 - geopy。
如果我有一个城市列表,例如
cities = ["New York, NY","Chicago, IL","Denver, CO"]
我有他们的经纬度:
location = [(40.0149856, -105.2705456), (40.7127837, -74.0059413), (41.8781136, -87.6297982), (39.737567, -104.9847179)]
我的问题是:
我怎么能在python中写这个?或算法是什么?
答案 0 :(得分:0)
Geopy能够使用vincenty或great_circles计算距离。循环遍历列表,找到最小距离,将该距离添加到该位置的总弹出并重复。 类似的东西:
total = 0
while location != []:
test = float("inf")
for loc in location:
#do distance calc here set = to dist
if dist < test:
test = dist
temp = loc
total += test
location.remove(loc)