folium画轨迹 - xd21303/Notebook GitHub Wiki

import folium
from folium.features import DivIcon
from folium import plugins
import geohash2

map_gaode = folium.Map(
    tiles=
    'http://wprd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&scl=1&x={x}&y={y}&z={z}',
    attr='default')

route = []
hour_label = ''
for name, row in data.iterrows():
    if True:
        #     if row['curr_event_time']> datetime.strptime('2021-05-07 00:00:00', "%Y-%m-%d %H:%M:%S") \
        #     and row['curr_event_time']<datetime.strptime('2021-05-07 23:59:59', "%Y-%m-%d %H:%M:%S"):
        route.append([row["latgcj"], row["longcj"]])
        if row['positiontime'].hour != hour_label:
            folium.Marker(
                [row["latgcj"], row["longcj"]],
                icon=DivIcon(
                    icon_size=(250, 36),
                    icon_anchor=(0, 0),
                    html=
                    f"""<div style="font-size: 20pt">{row['positiontime'].hour}</div>""",
                )).add_to(map_gaode)
            hour_label = row['positiontime'].hour
        folium.CircleMarker(
            [row["latgcj"], row["longcj"]],
            radius=6,
            fill=True,
            fillColor='blue',
            popup=name,
            icon=DivIcon(
                icon_size=(150, 36),
                icon_anchor=(0, 0),
                html=f'<div style="font-size: 8pt; color:red;">{name}</div>',
            ),
            tooltip=str(name) + '   ' +
            str(row['positiontime'])).add_to(map_gaode)

        rec = geohash2.decode_exactly(row['hashcode'])
        bounds = [(rec[0] + rec[2], rec[1] + rec[3]),
                  (rec[0] - rec[2], rec[1] - rec[3])]
        folium.Rectangle(
            # 坐标列表, Latitude and Longitude of line (Northing, Easting)
            bounds=bounds,
            weight=2,  # 线条宽度
            color='red').add_to(map_gaode)
lc = folium.PolyLine(
    route,
    weight=2,  # 粗细
    opacity=0.8,  # 透明度
    color='orange').add_to(map_gaode)
attr = {
    "fill": "#007DEF",
    "font-weight": "bold",
    "font-size": "20"
}  # -->的颜色,加粗,大小
plugins.PolyLineTextPath(lc,
                         "\u279E  ",
                         repeat=True,
                         offset=0,
                         attributes=attr).add_to(map_gaode)
plugins.AntPath(locations=route,
                reverse=False,
                dash_array=[20, 30],
                color="blue").add_to(map_gaode)
folium.Marker([data.loc[0, 'latgcj'], data.loc[0, 'longcj']]).add_to(map_gaode)
folium.Marker([data.iloc[-1]['latgcj'], data.iloc[-1]['longcj']],
              icon=folium.Icon(color="red")).add_to(map_gaode)
map_gaode.fit_bounds(map_gaode.get_bounds())
map_gaode
⚠️ **GitHub.com Fallback** ⚠️