欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python folium应用——将经纬度在地图上标注

程序员文章站 2024-02-13 16:56:52
...
import folium
import pandas as pd

def marker(trajectory_df):
    trajectory = folium.map.FeatureGroup()
    for index,row in trajectory_df.iterrows():
        trajectory.add_child(
            folium.CircleMarker(
            [row['lat'],row['lon']],
            radius=0.2,
            popup=index,
#             tooltip=row['time_view']+" "+str(row['lon'])+" "+str(row['lat'])+" "+ str(row["topN_count"]),
            color='blue'
            )
        )

    return trajectory

def plot_data(jingwei):
    data = pd.DataFrame(jingwei)
    data.columns = ["lon","lat"]
    if len(data) >200:   #点数太多时进行抽样
        data = data.sample(frac=200/len(data))   
    data['lat'] = data['lat'].astype(float)
    data['lon'] = data['lon'].astype(float)
    # data=data.iloc[1:1500]
    data=data[data['lat']!=0]
    print (data.shape)

    # data.astype(float,inplace=True)
    # raw.columns=['latitude','longtitude','altitude','date','time']
    m = folium.Map(location=[data['lat'].mean(),data['lon'].mean()],zoom_start=12,width=800,height=600)
    m.add_child(marker(data))
    return m