Google Street View Example¶
This notebook demonstrates how to use the Google Street View feature in anymap's MapLibre implementation. The Street View control allows users to view street-level imagery at clicked locations on the map.
In [1]:
Copied!
from anymap import MapLibreMap
import os
from anymap import MapLibreMap
import os
Setup¶
Before using the Google Street View functionality, you need to have a Google Maps API key. You can:
- Set it as an environment variable:
GOOGLE_MAPS_API_KEY
- Pass it directly to the
add_google_streetview()
method - In Google Colab, add it to your userdata with key
GOOGLE_MAPS_API_KEY
Note: Make sure your Google Maps API key has the Street View Static API enabled.
Basic Street View Setup¶
Create a map centered in New York City and add the Google Street View control.
In [2]:
Copied!
# Create a map centered in New York City
m = MapLibreMap(
center=[-74.0066, 40.7135], # New York City coordinates
zoom=15,
height="600px",
width="100%",
)
# Add a basemap for better context
m.add_basemap("OpenStreetMap.Mapnik")
# Add the Google Street View control
# The API key will be automatically retrieved from the GOOGLE_MAPS_API_KEY environment variable
try:
m.add_google_streetview(position="top-left")
print("✅ Street View control added successfully!")
print("📍 How to use:")
print(" 1. Look for the Street View button on the map (person/peg man icon)")
print(" 2. Click and drag the pegman to show Street View coverage (blue areas)")
print(" 3. Drop the pegman on blue coverage areas to open Street View")
print(" 4. The plugin now properly initializes when the map loads")
except ValueError as e:
print(f"❌ Error: {e}")
print("💡 Please set your GOOGLE_MAPS_API_KEY environment variable")
m
# Create a map centered in New York City
m = MapLibreMap(
center=[-74.0066, 40.7135], # New York City coordinates
zoom=15,
height="600px",
width="100%",
)
# Add a basemap for better context
m.add_basemap("OpenStreetMap.Mapnik")
# Add the Google Street View control
# The API key will be automatically retrieved from the GOOGLE_MAPS_API_KEY environment variable
try:
m.add_google_streetview(position="top-left")
print("✅ Street View control added successfully!")
print("📍 How to use:")
print(" 1. Look for the Street View button on the map (person/peg man icon)")
print(" 2. Click and drag the pegman to show Street View coverage (blue areas)")
print(" 3. Drop the pegman on blue coverage areas to open Street View")
print(" 4. The plugin now properly initializes when the map loads")
except ValueError as e:
print(f"❌ Error: {e}")
print("💡 Please set your GOOGLE_MAPS_API_KEY environment variable")
m
❌ Error: Google Maps API key is required. Please provide it as a parameter or set the GOOGLE_MAPS_API_KEY environment variable. 💡 Please set your GOOGLE_MAPS_API_KEY environment variable
Out[2]: