如何在Python(Jupyter Notebooks)中在Map上显示路线?

xoefb8l8  于 2023-04-19  发布在  Python
关注(0)|答案(1)|浏览(98)

我有一个包含伊朗一些纬度和经度的excel文件。我想在Jupyter中用python在Map上准确地显示到这些位置的路线。
我尝试了很多方法,但我无法访问付费API。我使用了osmnx,它无法在Map上显示我所在位置的路线。

b4lqfgs4

b4lqfgs41#

试试这个方法;

import pandas as pd
    import folium

    # Read the Excel file with the latitudes and longitudes
    data = pd.read_excel('your_excel_file.xlsx')

    # Create a map centered on Iran
    iran_map = folium.Map(location=[32.4279, 53.6880], zoom_start=5)

    # Loop through the data and add markers for each location
    for i, row in data.iterrows():
        folium.Marker([row['Latitude'], row['Longitude']], 
                    popup=row['Location']).add_to(iran_map)

    # Add a line to connect the markers
    locations = data[['Latitude', 'Longitude']].values.tolist()
    folium.PolyLine(locations, color='red').add_to(iran_map)

    # Show the map
    iran_map

相关问题