我有一个函数(mymap.addpoint来自pygmap模块),它需要两个浮点参数。我有一个for循环,它在列表中为每个城市生成纬度和经度。我想使用这些坐标将多个点(标记或引脚)添加到google地图中,但我不知道如何将它们作为参数输入。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函数。我仍在努力弄清楚如何在函数中传递两个参数一次,然后再进行多次,如果有任何意义的话。
这不起作用,因为需要两个are:
regions_map.addpoint(point)我尝试过这样做,但这两个参数似乎被视为字符串而不是浮动:
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 (All Digital)', 'Almont Township, MI', 'Alpena, MI', >'Arnold Lake/Hayes, MI (All Digital)', 'Au Gres, MI' (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 regions_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行,在绘图点 TypeError:需要浮动参数,而不是str
如何使用for循环(或其他什么)来生成多个点,将坐标作为函数的参数传递?
我是个很好的谷歌人,但这个很难。我甚至不知道怎么去找它。谢谢
发布于 2014-04-03 07:57:38
错误表示addpoint()函数需要参数作为浮点,您将它们作为字符串传递。您所需要的只是将它们解析为浮点数:
regions_map.addpoint(float(lat), float(long))https://stackoverflow.com/questions/22830879
复制相似问题