React Google Maps Library - Basic Map Stay organized with collections Save and categorize content based on your preferences.
Page Summary
This example demonstrates how to render a basic Google Map in a React application using the
vis.gl/react-google-mapslibrary.The
vis.gl/react-google-mapslibrary provides React components and hooks for integrating the Google Maps JavaScript API, but it's important to note it is open source and not officially supported by Google.The example includes code snippets for TypeScript, JavaScript, CSS, and HTML, showcasing the implementation of the map within a simple web page.
Users can try the sample directly in Google Cloud Shell or clone the repository and run it locally using Git and Node.js.
While the library itself is open source, any Google Maps Platform services utilized within it are subject to the Google Maps Platform Terms of Service.
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.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-12-11 UTC.