React Google Maps Library - Basic Map Stay organized with collections Save and categorize content based on your preferences.
This example uses thevis.gl/react-google-maps opensource library to render a Google map in a React app. Thevis.gl/react-google-maps libraryis a collection of React components and hooks for the Google Maps JavaScriptAPI.
Important: Thevis.gl/react-google-maps libraryis offered 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 onGitHub .TypeScript
importReactfrom'react';import{createRoot}from'react-dom/client';import{APIProvider,Map}from'@vis.gl/react-google-maps';constAPI_KEY=globalThis.GOOGLE_MAPS_API_KEY??("YOUR_API_KEY");constApp=()=>(<APIProvidersolutionChannel='GMP_devsite_samples_v3_rgmbasicmap'apiKey={API_KEY}><MapdefaultZoom={8}defaultCenter={{ lat: -34.397, lng: 150.644 }}gestureHandling={'greedy'}disableDefaultUI={true}/></APIProvider>);constroot=createRoot(document.getElementById('app')!);root.render(<App/>);exportdefaultApp;
JavaScript
importReactfrom"react";import{createRoot}from"react-dom/client";import{APIProvider,Map}from"@vis.gl/react-google-maps";constAPI_KEY=globalThis.GOOGLE_MAPS_API_KEY??"YOUR_API_KEY";constApp=()=>(<APIProvidersolutionChannel="GMP_devsite_samples_v3_rgmbasicmap"apiKey={API_KEY}><MapdefaultZoom={8}defaultCenter={{ lat: -34.397, lng: 150.644 }}gestureHandling={"greedy"}disableDefaultUI={true}/></APIProvider>);constroot=createRoot(document.getElementById("app"));root.render(<App/>);exportdefaultApp;
CSS
body{margin:0;font-family:sans-serif;}#app{width:100vw;height:100vh;}
HTML
<html> <head> <title>React Google Maps - Basic Map</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-basic-maphttps://github.com/googlemaps/js-samples.git
cdjs-samples
npmi
npmstart
Other samples can be tried by switching to any branch beginning withsample-SAMPLE_NAME
.
gitcheckoutsample-SAMPLE_NAME
npmi
npmstart
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-07-18 UTC.