当然可以。使用PolyLine https://python-visualization.github.io/folium/modules.html#folium.vector_layers.PolyLine:
import folium
m = folium.Map(location=[40.720, -73.993],
zoom_start=15)
loc = [(40.720, -73.993),
(40.721, -73.996)]
folium.PolyLine(loc,
color='red',
weight=15,
opacity=0.8).add_to(m)
m
你得到:
EDIT 1
为了画一个步行道在两点之间,您可以使用以下组合OSMnx https://github.com/gboeing/osmnx and networkx https://networkx.github.io/:
import osmnx as ox
import networkx as nx
ox.config(log_console=True,
use_cache=True)
G_walk = ox.graph_from_place('Manhattan Island, New York City, New York, USA',
network_type='walk')
orig_node = ox.get_nearest_node(G_walk,
(40.748441, -73.985664))
dest_node = ox.get_nearest_node(G_walk,
(40.748441, -73.4))
route = nx.shortest_path(G_walk, orig_node, dest_node, weight='length')
fig, ax = ox.plot_graph_route(G_walk,
route,
node_size=0,
save=True,
file_format='svg',
filename='test')
你得到:
EDIT 2
对于 folium 类型的地图,您可以使用plot_route_folium https://osmnx.readthedocs.io/en/stable/osmnx.html#osmnx.plot.plot_route_folium:
import osmnx as ox
import networkx as nx
ox.config(log_console=True, use_cache=True)
G_walk = ox.graph_from_place('Manhattan Island, New York City, New York, USA',
network_type='walk')
orig_node = ox.get_nearest_node(G_walk,
(40.748441, -73.985664))
dest_node = ox.get_nearest_node(G_walk,
(40.748441, -73.4))
route = nx.shortest_path(G_walk,
orig_node,
dest_node,
weight='length')
route_map = ox.plot_route_folium(G_walk, route)
route_map.save('route.html')
你会得到一个有用的 html 文件: