reviews Get a Maps Demo Key: Try out select Maps JavaScript API and Places UI Kit features at no cost with a Maps Demo Key—no billing information required.
import{setOptions,importLibrary}from'@googlemaps/js-api-loader';constAPI_KEY='GOOGLE_MAPS_API_KEY';constcenter={lat:41.90476224706472,lng:12.49822074385094};constzoom=14;consturl='https://maps.googleapis.com/maps/api/staticmap';functioninit():void{constwrapper=document.getElementById('wrapper')asHTMLButtonElement;// The Maps Static API limits size to 640x640.// We cap the requested dimensions and explicitly set the CSS background-size// to match so that POI icons and text render at the exact same physical scale// as the interactive map, rather than being stretched by background-size: cover.constreqWidth=Math.min(640,wrapper.clientWidth||640);constreqHeight=Math.min(640,wrapper.clientHeight||640);constscale=window.devicePixelRatio>=2?2:1;wrapper.style.backgroundImage=`url(${url}?center=${String(center.lat)},${String(center.lng)}&zoom=${String(zoom)}&scale=${String(scale)}&size=${String(reqWidth)}x${String(reqHeight)}&key=${API_KEY})`;wrapper.style.backgroundSize=`${String(reqWidth)}px ${String(reqHeight)}px`;wrapper.style.backgroundRepeat='no-repeat';wrapper.style.backgroundPosition='center';wrapper.addEventListener('click',()=>{wrapper.remove();setOptions({key:API_KEY,});voidimportLibrary('maps').then(({Map})=>{newMap(document.getElementById('map')!,{center,zoom,mapId:'DEMO_MAP_ID',});});});}document.addEventListener('DOMContentLoaded',()=>{init();});export{};
import{setOptions,importLibrary}from'@googlemaps/js-api-loader';constAPI_KEY='GOOGLE_MAPS_API_KEY';constcenter={lat:41.90476224706472,lng:12.49822074385094};constzoom=14;consturl='https://maps.googleapis.com/maps/api/staticmap';functioninit(){constwrapper=document.getElementById('wrapper');// The Maps Static API limits size to 640x640.// We cap the requested dimensions and explicitly set the CSS background-size// to match so that POI icons and text render at the exact same physical scale// as the interactive map, rather than being stretched by background-size: cover.constreqWidth=Math.min(640,wrapper.clientWidth||640);constreqHeight=Math.min(640,wrapper.clientHeight||640);constscale=window.devicePixelRatio>=2?2:1;wrapper.style.backgroundImage=`url(${url}?center=${String(center.lat)},${String(center.lng)}&zoom=${String(zoom)}&scale=${String(scale)}&size=${String(reqWidth)}x${String(reqHeight)}&key=${API_KEY})`;wrapper.style.backgroundSize=`${String(reqWidth)}px ${String(reqHeight)}px`;wrapper.style.backgroundRepeat='no-repeat';wrapper.style.backgroundPosition='center';wrapper.addEventListener('click',()=>{wrapper.remove();setOptions({key:API_KEY,});voidimportLibrary('maps').then(({Map})=>{newMap(document.getElementById('map'),{center,zoom,mapId:'DEMO_MAP_ID',});});});}document.addEventListener('DOMContentLoaded',()=>{init();});
/* * Always set the map height explicitly to define the size of the div element * that contains the map. */#map{height:100%;}/* * Optional: Makes the sample page fill the window. */html,body{height:100%;margin:0;padding:0;}:root{--mdc-theme-primary:#1a73e8;}#wrapper{width:100%;height:100%;display:flex;align-items:center;justify-content:center;cursor:pointer;}
Git and Node.js are required to run this sample locally. Follow these instructions
to install Node.js and NPM. You will also need a Google Maps API key.
The following commands clone the repository, install dependencies, and copy the environment file.
Once you copy the environment file, make sure to open the .env file and replace <Insert your own development API key here> with your actual API key before starting the sample.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-23 UTC."],[],[]]