我有几个车辆路径,我想要自动绘制他们在不同的文件。我试图用for循环来完成这个任务,但是这些点在下面的每个文件上都是重叠的。所以,基本上,在最后一个文件中,我有所有的路径。
这是我的职责。有人能帮我吗?
def drawUnique(uniqueVeh):
for i in uniqueVeh:
latitudes = list(map(float,list(gps_data[gps_data["id"] == i]["lat"])))
longitudes = list(map(float,list(gps_data[gps_data["id"] == i]["long"])))
gmap.scatter(latitudes, longitudes, size=10, marker=False)
gmap.draw("map" + i + ".html")发布于 2017-10-03 17:25:37
该问题与gmap对象的声明有关,该声明显然是在循环之前进行的,因此使用同一个对象并保存所有标记。
您只需要在每次迭代开始时定义一个新的gmap对象,就可以创建一个新的新映射:
def drawUnique(uniqueVeh):
for i in uniqueVeh:
gmap = gmplot.GoogleMapPlotter(center_lat, center_lng, zoom) # replace the values !!
latitudes = list(map(float,list(gps_data[gps_data["id"] == i]["lat"])))
longitudes = list(map(float,list(gps_data[gps_data["id"] == i]["long"])))
gmap.scatter(latitudes, longitudes, size=10, marker=False)
gmap.draw("map" + i + ".html")基本上,问题中的代码可以转换如下:
import gmplot
gmap = gmplot.GoogleMapPlotter(40.640, -73.926, 16)
# turn 1
gmap.scatter([40.642810, 40.638240],
[-73.915, -73.922901],
'cornflowerblue', edge_width=8)
gmap.draw("map1.html")
# turn 2
# same gmap : all marks are added and overlap the first
gmap.scatter([40.644494, 40.637083],
[-73.925044, -73.926464],
'red', edge_width=8)
gmap.draw("map2.html")您需要在每幅绘图之间插入这一行,以避免map2.html中的重叠问题:
gmap = gmplot.GoogleMapPlotter(40.640, -73.926, 16)https://stackoverflow.com/questions/46538114
复制相似问题