我有一个需要 2 个浮点参数的函数(来自 pygmaps 模块的 mymap.addpoint) 。我有一个 for 循环,可以为列表中的每个城市生成纬度和经度。我想使用这些坐标将多个点(标记或大头针)添加到谷歌地图,但我不知道如何将它们作为参数输入。map_regions 是城市列表:
print map_regions
for item in map_regions:
try:
geo = Geocoder.geocode(item)
except:
pass
else:
point = (geo[0].coordinates)
print point
regions_map.addpoint(lat, long)
我意识到上面的代码没有在 for 循环中包含 addpoint 函数。我仍在试图弄清楚如何在函数中只传递 2 个参数,然后再多次传递,如果这有任何意义的话。
这不起作用,因为需要两个参数:
regions_map.addpoint(point)
我试过了,但似乎 2 个参数被视为字符串而不是浮点数:
for item in map_regions:
try:
geo = Geocoder.geocode(item)
except:
pass
else:
point = (geo[0].coordinates)
joint = ', '.join(map(str, point))
split_point = joint.split(',', 2)
lat = split_point[0]
lon = split_point[1]
print point
regions_map.addpoint(lat, long)
这是我得到的错误:
['MI','Allegan,MI','Alma,MI(全数字)','Almont Township,MI','Alpena,MI',>'Arnold Lake/Hayes,MI(全数字)','Au格雷斯,密歇根']
(44.3148443,-85.60236429999999)
(42.5291989, -85.8553031)
(43.3789199, -84.6597274)
(42.9450131,-83.05761559999999)
(45.0616794, -83.4327528)
(45.0616794, -83.4327528)
(44.0486294, -83.6958161)
回溯(最近一次通话最后):
文件“/Users/digital1/Dropbox/Programming/Map_Locations/gmaps.py”,第 82 行,在 gmaps_mapit()
文件“/Users/digital1/Dropbox/Programming/Map_Locations/gmaps.py”,第 78 行,位于 >gmaps_mapit region_map.draw('./mymap.html')
绘图中的文件“build/bdist.macosx-10.6-intel/egg/pygmaps.py”,第 48 行
文件“build/bdist.macosx-10.6-intel/egg/pygmaps.py”,第 83 行,在绘图点中
文件“build/bdist.macosx-10.6-intel/egg/pygmaps.py”,第 129 行,在 drawpoint
类型错误:需要浮点参数,而不是 str
如何使用 for 循环(或其他)将坐标作为函数的参数传递以生成多个点?
我是一个很好的谷歌用户,但这个很难。我什至不知道如何搜索它。谢谢