Places UI Kit: A ready-to-use library that provides room for customization and low-code development. Try it out, and share yourinput on your UI Kit experience.

React Google Maps Library - Extended Component Library

  • This example demonstrates building a location services web app using Google Maps Platform's Extended Component Library and the vis.gl/react-google-maps library.

  • The Extended Component Library provides pre-built UI elements simplifying complex map interactions, while vis.gl/react-google-maps offers React components for Google Maps integration.

  • Users can search for colleges in the US or Canada, view place details, reviews, and get directions.

  • The sample code includes TypeScript and JavaScript versions, along with CSS and HTML for styling and structure.

  • The application can be run locally by cloning the repository, installing dependencies, and starting the application with provided commands.

This example shows how to build a basic locations services web app using theGoogle Maps Platform's Extended Component Librarywith thevis.gl/react-google-mapsopen source library.

Google Maps Platform's Extended ComponentLibrary isa set of Web Components that helps developers build better maps faster, and withless effort. It encapsulates boilerplate code, best practices, and responsivedesign, reducing complex map UIs into what is effectively a single HTML element.These components make it easier to read, learn, customize, and maintainmaps-related code.

Thevis.gl/react-google-mapslibrary is a collection of React components and hooks for the Google MapsJavaScript API.

Important: Thevis.gl/react-google-maps libraryand theExtended ComponentLibrary areoffered using an open source license. It is not governed by the Google MapsPlatform Support Technical Support Services Guidelines, the SLA, or theDeprecation Policy (however, any Google Maps Platform services used by thelibrary remain subject to the Google Maps Platform Terms of Service). If youfind a bug, or have a feature request, file an issue on the respective librarysite.

TypeScript

importReact,{useState,useRef}from'react';importReactDOMfrom'react-dom/client';import{AdvancedMarker,Map,Pin,APIProvider}from'@vis.gl/react-google-maps';import{PlaceReviews,PlaceDataProvider,PlaceDirectionsButton,IconButton,PlaceOverview,SplitLayout,OverlayLayout,PlacePicker}from'@googlemaps/extended-component-library/react';/** * The below imports are necessary because we are creating refs of * the OverlayLayout and PlacePicker components. You need to pass * the ref property a web component type object. Imports from * @googlemaps/extended-component-library/react are wrappers around * the web components, not the components themselves. For the ref * property we import the actual components and alias them for clarity. */import{OverlayLayoutasTOverlayLayout}from'@googlemaps/extended-component-library/overlay_layout.js';import{PlacePickerasTPlacePicker}from'@googlemaps/extended-component-library/place_picker.js';constAPI_KEY=globalThis.GOOGLE_MAPS_API_KEY??("YOUR_API_KEY");constDEFAULT_CENTER={lat:38,lng:-98};constDEFAULT_ZOOM=4;constDEFAULT_ZOOM_WITH_LOCATION=16;/** * Sample app that helps users locate a college on the map, with place info such * as ratings, photos, and reviews displayed on the side. */constApp=()=>{constoverlayLayoutRef=useRef<TOverlayLayout>(null);constpickerRef=useRef<TPlacePicker>(null);const[college,setCollege]=useState<google.maps.places.Place|undefined>(undefined);/**   * See https://lit.dev/docs/frameworks/react/#using-slots for why   * we need to wrap our custom elements in a div with a slot attribute.   */return(<divclassName="App"><APIProvidersolutionChannel='GMP_devsite_samples_v3_rgmcollegepicker'apiKey={API_KEY}version='beta'><SplitLayoutrowReverserowLayoutMinWidth={700}><divclassName="SlotDiv"slot="fixed"><OverlayLayoutref={overlayLayoutRef}><divclassName="SlotDiv"slot="main"><PlacePickerclassName="CollegePicker"ref={pickerRef}forMap="gmap"country={['us','ca']}type="university"placeholder="Enter a college in the US or Canada"onPlaceChange={()=>{if(!pickerRef.current?.value){setCollege(undefined);}else{setCollege(pickerRef.current?.value);}}}/><PlaceOverviewsize="large"place={college}googleLogoAlreadyDisplayed><divslot="action"className="SlotDiv"><IconButtonslot="action"variant="filled"onClick={()=>overlayLayoutRef.current?.showOverlay()}>SeeReviews</IconButton></div><divslot="action"className="SlotDiv"><PlaceDirectionsButtonslot="action"variant="filled">Directions</PlaceDirectionsButton></div></PlaceOverview></div><divslot="overlay"className="SlotDiv"><IconButtonclassName="CloseButton"onClick={()=>overlayLayoutRef.current?.hideOverlay()}>Close</IconButton><PlaceDataProviderplace={college}><PlaceReviews/></PlaceDataProvider></div></OverlayLayout></div><divclassName="SplitLayoutContainer"slot="main"><Mapid="gmap"mapId="8c732c82e4ec29d9"center={college?.location??DEFAULT_CENTER}zoom={college?.location?DEFAULT_ZOOM_WITH_LOCATION:DEFAULT_ZOOM}gestureHandling="none"fullscreenControl={false}zoomControl={false}>{college?.location &&(<AdvancedMarkerposition={college?.location}><Pinbackground={'#FBBC04'}glyphColor={'#000'}borderColor={'#000'}/></AdvancedMarker>)}</Map></div></SplitLayout></APIProvider></div>);};constroot=ReactDOM.createRoot(document.getElementById('root')!);root.render(<React.StrictMode><App/></React.StrictMode>);
Note: Read theguide on using TypeScript and Google Maps.

JavaScript

importReact,{useState,useRef}from"react";importReactDOMfrom"react-dom/client";import{AdvancedMarker,Map,Pin,APIProvider,}from"@vis.gl/react-google-maps";import{PlaceReviews,PlaceDataProvider,PlaceDirectionsButton,IconButton,PlaceOverview,SplitLayout,OverlayLayout,PlacePicker,}from"@googlemaps/extended-component-library/react";constAPI_KEY=globalThis.GOOGLE_MAPS_API_KEY??"YOUR_API_KEY";constDEFAULT_CENTER={lat:38,lng:-98};constDEFAULT_ZOOM=4;constDEFAULT_ZOOM_WITH_LOCATION=16;/** * Sample app that helps users locate a college on the map, with place info such * as ratings, photos, and reviews displayed on the side. */constApp=()=>{constoverlayLayoutRef=useRef(null);constpickerRef=useRef(null);const[college,setCollege]=useState(undefined);/**   * See https://lit.dev/docs/frameworks/react/#using-slots for why   * we need to wrap our custom elements in a div with a slot attribute.   */return(<divclassName="App"><APIProvidersolutionChannel="GMP_devsite_samples_v3_rgmcollegepicker"apiKey={API_KEY}version="beta"><SplitLayoutrowReverserowLayoutMinWidth={700}><divclassName="SlotDiv"slot="fixed"><OverlayLayoutref={overlayLayoutRef}><divclassName="SlotDiv"slot="main"><PlacePickerclassName="CollegePicker"ref={pickerRef}forMap="gmap"country={["us","ca"]}type="university"placeholder="Enter a college in the US or Canada"onPlaceChange={()=>{if(!pickerRef.current?.value){setCollege(undefined);}else{setCollege(pickerRef.current?.value);}}}/><PlaceOverviewsize="large"place={college}googleLogoAlreadyDisplayed><divslot="action"className="SlotDiv"><IconButtonslot="action"variant="filled"onClick={()=>overlayLayoutRef.current?.showOverlay()}>SeeReviews</IconButton></div><divslot="action"className="SlotDiv"><PlaceDirectionsButtonslot="action"variant="filled">Directions</PlaceDirectionsButton></div></PlaceOverview></div><divslot="overlay"className="SlotDiv"><IconButtonclassName="CloseButton"onClick={()=>overlayLayoutRef.current?.hideOverlay()}>Close</IconButton><PlaceDataProviderplace={college}><PlaceReviews/></PlaceDataProvider></div></OverlayLayout></div><divclassName="SplitLayoutContainer"slot="main"><Mapid="gmap"mapId="8c732c82e4ec29d9"center={college?.location??DEFAULT_CENTER}zoom={college?.location?DEFAULT_ZOOM_WITH_LOCATION:DEFAULT_ZOOM}gestureHandling="none"fullscreenControl={false}zoomControl={false}>{college?.location &&(<AdvancedMarkerposition={college?.location}><Pinbackground={"#FBBC04"}glyphColor={"#000"}borderColor={"#000"}/></AdvancedMarker>)}</Map></div></SplitLayout></APIProvider></div>);};constroot=ReactDOM.createRoot(document.getElementById("root"));root.render(<React.StrictMode><App/></React.StrictMode>,);
Note: The JavaScript is compiled from the TypeScript snippet.

CSS

body{margin:0;font-family:sans-serif;}#root{width:100vw;height:100vh;}.App{--gmpx-color-surface:#f6f5ff;--gmpx-color-on-primary:#f8e8ff;--gmpx-color-on-surface:#000;--gmpx-color-on-surface-variant:#636268;--gmpx-color-primary:#8a5cf4;--gmpx-fixed-panel-height-column-layout:420px;--gmpx-fixed-panel-width-row-layout:340px;background:var(--gmpx-color-surface);inset:0;position:fixed;}.MainContainer{display:flex;flex-direction:column;}.SplitLayoutContainer{height:100%;}.CollegePicker{--gmpx-color-surface:#fff;flex-grow:1;margin:1rem;}.CloseButton{display:block;margin:1rem;}.SlotDiv{display:contents;}

HTML

<html>  <head>    <title>React Google Maps - College Picker App</title>    <link rel="stylesheet" type="text/css" href="./style.css" />  </head>  <body>    <div></div>    <script type="module" src="./index"></script>  </body></html>

Try Sample

Clone Sample

Git and Node.js are required to run this sample locally. Follow theseinstructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.

gitclone-bsample-rgm-college-pickerhttps://github.com/googlemaps/js-samples.gitcdjs-samplesnpminpmstart

Other samples can be tried by switching to any branch beginning withsample-SAMPLE_NAME.

gitcheckoutsample-SAMPLE_NAMEnpminpmstart

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-21 UTC.