Random Marker Map Generation with Folium

  • Share this:

Code introduction


This function creates a map using the Folium library and adds a random number of markers to it.


Technology Stack : Folium, NumPy

Code Type : Map tag generation

Code Difficulty : Intermediate


                
                    
def random_marker_map(center, zoom_level):
    import folium
    import random
    import numpy as np

    # Create a map centered on the given coordinates with the specified zoom level
    m = folium.Map(location=center, zoom_start=zoom_level)

    # Generate random coordinates around the center point
    num_markers = random.randint(5, 15)
    for _ in range(num_markers):
        random_lat = center[0] + np.random.normal(0, 0.05)
        random_lon = center[1] + np.random.normal(0, 0.05)
        folium.Marker([random_lat, random_lon]).add_to(m)

    return m                
              
Tags: