You can download this code by clicking the button below.
This code is now available for download.
This function creates a Google map and adds markers at specified locations.
Technology Stack : Bokeh, GMapOptions, GMapWidget, Circle
Code Type : Bokeh visualization
Code Difficulty : Intermediate
import random
from bokeh.plotting import figure, show
from bokeh.models import Circle, GMapOptions, GMapWidget
from bokeh.layouts import row
def create_map_with_markers(lat, lng, zoom, markers):
"""
Create a Google Map with specified latitude, longitude, zoom level, and markers.
"""
# Create a figure for the map
p = figure(title="Google Map with Markers", tools="pan,wheel_zoom,box_zoom,reset", plot_width=800, plot_height=600)
# Set the map options
gmap_options = GMapOptions(lat=lat, lng=lng, zoom=zoom)
# Add the GMapWidget to the figure
gmap_widget = GMapWidget(map_options=gmap_options)
p.add_layout(gmap_widget)
# Add markers to the map
for marker in markers:
lat, lng, label = marker
circle = Circle(x=lng, y=lat, size=10, fill_color="red", line_color=None)
p.add_layout(circle, 'below')
p.add_layout(label, 'below')
# Display the map
show(p)
# Example usage
markers = [(34.0522, -118.2437, "Los Angeles"), (40.7128, -74.0060, "New York")]
create_map_with_markers(37.7749, -122.4194, 10, markers)