Google maps plugin for Jupyter notebooks with interactive visualization capabilities
—
Display real-time and static transportation information including traffic conditions, public transit routes, and bicycling paths. These layers provide contextual information about transportation infrastructure and current conditions.
Display real-time traffic information with automatic updates and current road conditions.
def traffic_layer(auto_refresh=True):
"""
Create a traffic information layer.
Parameters:
- auto_refresh (bool): Whether layer auto-updates traffic data
Returns:
Traffic: Traffic layer instance
"""Widget for displaying current traffic conditions on roads.
class Traffic:
"""
Traffic layer widget showing current traffic conditions.
Attributes:
- auto_refresh (bool): Whether layer auto-updates
"""Display public transportation routes and stops including buses, trains, and subway systems.
def transit_layer():
"""
Create a public transit layer.
Returns:
Transit: Transit layer instance
"""Widget for showing public transportation infrastructure.
class Transit:
"""
Transit layer widget showing public transport routes and stops.
"""Display bicycle-friendly routes and cycling infrastructure.
def bicycling_layer():
"""
Create a bicycling routes layer.
Returns:
Bicycling: Bicycling layer instance
"""Widget for showing bicycle routes and cycling infrastructure.
class Bicycling:
"""
Bicycling layer widget showing bike routes and cycling infrastructure.
"""import gmaps
gmaps.configure(api_key="YOUR_API_KEY")
# Create figure with traffic layer
fig = gmaps.figure(center=(37.7749, -122.4194), zoom_level=12)
traffic_layer = gmaps.traffic_layer()
fig.add_layer(traffic_layer)
# Traffic conditions will be displayed in real-time
figimport gmaps
gmaps.configure(api_key="YOUR_API_KEY")
# Static traffic snapshot
fig = gmaps.figure()
traffic_layer = gmaps.traffic_layer(auto_refresh=False)
fig.add_layer(traffic_layer)
figimport gmaps
gmaps.configure(api_key="YOUR_API_KEY")
# Show public transportation routes
fig = gmaps.figure(center=(37.7749, -122.4194), zoom_level=12)
transit_layer = gmaps.transit_layer()
fig.add_layer(transit_layer)
# Bus routes, train lines, and subway systems will be displayed
figimport gmaps
gmaps.configure(api_key="YOUR_API_KEY")
# Show bicycle-friendly routes
fig = gmaps.figure(center=(37.7749, -122.4194), zoom_level=13)
bicycling_layer = gmaps.bicycling_layer()
fig.add_layer(bicycling_layer)
# Bike lanes, trails, and cycling routes will be displayed
figimport gmaps
gmaps.configure(api_key="YOUR_API_KEY")
# Create figure focused on urban area
fig = gmaps.figure(
center=(37.7749, -122.4194), # San Francisco
zoom_level=12
)
# Add traffic information
traffic = gmaps.traffic_layer()
fig.add_layer(traffic)
# Add public transit routes
transit = gmaps.transit_layer()
fig.add_layer(transit)
# Add bicycling routes
bicycling = gmaps.bicycling_layer()
fig.add_layer(bicycling)
# All transportation modes are now visible
figimport gmaps
gmaps.configure(api_key="YOUR_API_KEY")
fig = gmaps.figure(center=(37.7749, -122.4194), zoom_level=13)
# Add transportation layers
traffic = gmaps.traffic_layer()
transit = gmaps.transit_layer()
fig.add_layer(traffic)
fig.add_layer(transit)
# Add markers for transit stations or important locations
transit_stations = [
(37.7749, -122.4194), # Downtown station
(37.7849, -122.4094), # Midtown station
(37.7949, -122.3994) # Uptown station
]
markers = gmaps.marker_layer(
transit_stations,
label=['Downtown', 'Midtown', 'Uptown'],
hover_text=['Main Transit Hub', 'Shopping District', 'Residential Area']
)
fig.add_layer(markers)
figimport gmaps
gmaps.configure(api_key="YOUR_API_KEY")
fig = gmaps.figure(center=(37.7749, -122.4194), zoom_level=12)
# Add transportation context layers
traffic = gmaps.traffic_layer()
bicycling = gmaps.bicycling_layer()
fig.add_layer(traffic)
fig.add_layer(bicycling)
# Add driving route
start = (37.7749, -122.4194)
end = (37.7849, -122.4094)
driving_route = gmaps.directions_layer(
start, end,
travel_mode='DRIVING',
stroke_color='blue',
stroke_weight=4.0
)
fig.add_layer(driving_route)
# Add cycling alternative
cycling_route = gmaps.directions_layer(
start, end,
travel_mode='BICYCLING',
stroke_color='green',
stroke_weight=3.0
)
fig.add_layer(cycling_route)
figimport gmaps
import gmaps.datasets
gmaps.configure(api_key="YOUR_API_KEY")
fig = gmaps.figure(center=(37.7749, -122.4194), zoom_level=11)
# Add all transportation layers for comprehensive view
traffic = gmaps.traffic_layer()
transit = gmaps.transit_layer()
bicycling = gmaps.bicycling_layer()
fig.add_layer(traffic)
fig.add_layer(transit)
fig.add_layer(bicycling)
# Add data layer (e.g., taxi pickups to show transportation demand)
try:
taxi_data = gmaps.datasets.load_dataset_as_df('taxi_rides')
pickup_locations = taxi_data[['pickup_latitude', 'pickup_longitude']]
# Create heatmap of transportation demand
demand_heatmap = gmaps.heatmap_layer(
pickup_locations,
opacity=0.6,
max_intensity=10,
gradient=['rgba(0,0,255,0)', 'rgba(0,0,255,1)', 'rgba(255,0,0,1)']
)
fig.add_layer(demand_heatmap)
except:
# Dataset not available, skip
pass
figimport gmaps
import time
gmaps.configure(api_key="YOUR_API_KEY")
# Create traffic monitoring setup
fig = gmaps.figure(
center=(37.7749, -122.4194),
zoom_level=12,
map_type='ROADMAP'
)
# Traffic layer with auto-refresh enabled
traffic = gmaps.traffic_layer(auto_refresh=True)
fig.add_layer(traffic)
# Add key intersections or highways as markers
key_locations = [
(37.7749, -122.4194), # Downtown
(37.7849, -122.4094), # Highway entrance
(37.7649, -122.4294) # Bridge approach
]
markers = gmaps.marker_layer(
key_locations,
label=['DT', 'HW', 'BR'],
hover_text=['Downtown Core', 'Highway On-ramp', 'Bridge Approach']
)
fig.add_layer(markers)
# Traffic conditions will update automatically
figimport gmaps
gmaps.configure(api_key="YOUR_API_KEY")
fig = gmaps.figure(center=(37.7749, -122.4194), zoom_level=12)
# Show all transportation options
transit = gmaps.transit_layer()
bicycling = gmaps.bicycling_layer()
fig.add_layer(transit)
fig.add_layer(bicycling)
# Add accessible locations
accessible_locations = [
(37.7749, -122.4194), # Wheelchair accessible station
(37.7849, -122.4094), # Bike share station
(37.7649, -122.4294) # Park & ride facility
]
accessibility_symbols = gmaps.symbol_layer(
accessible_locations,
fill_color=['blue', 'green', 'orange'],
scale=[5, 4, 4],
hover_text=[
'Wheelchair Accessible Transit',
'Bike Share Station',
'Park & Ride Facility'
]
)
fig.add_layer(accessibility_symbols)
figInstall with Tessl CLI
npx tessl i tessl/pypi-gmaps