1. Loading the API
Google Maps needs an API key (create one in the Google Cloud console with the Maps JavaScript API enabled) and is loaded asynchronously:
import { setOptions, importLibrary } from '@googlemaps/js-api-loader';
setOptions({ key: 'YOUR_GOOGLE_MAPS_API_KEY', v: 'weekly' });
const { Map } = await importLibrary('maps');
About the key in this live editor
The example below expects a key to be baked in when this site is built (locally: set GOOGLE_MAPS_API_KEY in .env and run uv run python scripts/generate_keys.py; on Cloudflare Pages it comes from a build environment variable). If no key was provided, the preview shows a notice instead of a map.