Create and Save Custom Location Map with Folium

  • Share this:

Code introduction


This function creates a map based on a specified location using the Folium library, adds a marker to the map, and then saves the map as an HTML file.


Technology Stack : Folium

Code Type : Geographic Information System (GIS)

Code Difficulty : Intermediate


                
                    
def create_random_map(location, zoom_level):
    import folium
    # Create a map centered at the specified location with the specified zoom level
    m = folium.Map(location=location, zoom=zoom_level)
    # Add a marker to the map at the specified location
    folium.Marker(location).add_to(m)
    # Save the map to an HTML file
    m.save("random_map.html")
    return m                
              
Tags: