Stay organized with collections
Save and categorize content based on your preferences.
This example uses the
vis.gl/react-google-maps open
source library to render a Google map in a React app. The
vis.gl/react-google-maps library
is a collection of React components and hooks for the Google Maps JavaScript
API.
Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.
[[["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 2025-08-26 UTC."],[[["\u003cp\u003eThis example demonstrates how to render a basic Google Map in a React application using the \u003ccode\u003evis.gl/react-google-maps\u003c/code\u003e library.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003evis.gl/react-google-maps\u003c/code\u003e library 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.\u003c/p\u003e\n"],["\u003cp\u003eThe example includes code snippets for TypeScript, JavaScript, CSS, and HTML, showcasing the implementation of the map within a simple web page.\u003c/p\u003e\n"],["\u003cp\u003eUsers can try the sample directly in Google Cloud Shell or clone the repository and run it locally using Git and Node.js.\u003c/p\u003e\n"],["\u003cp\u003eWhile the library itself is open source, any Google Maps Platform services utilized within it are subject to the Google Maps Platform Terms of Service.\u003c/p\u003e\n"]]],["This content demonstrates how to render a Google map in a React app using the `@vis.gl/react-google-maps` library. Key actions include importing necessary components (`APIProvider`, `Map`), setting an API key, and rendering the map. The map's default zoom, center, gesture handling, and UI elements are configurable through props. The provided code includes TypeScript, JavaScript, CSS, and HTML examples. The guide also details how to run the sample locally or through the cloud shell.\n"],null,["# React Google Maps Library - Basic Map\n\nThis example uses the\n[vis.gl/react-google-maps](https://visgl.github.io/react-google-maps/) open\nsource library to render a Google map in a React app. The\n[vis.gl/react-google-maps](https://visgl.github.io/react-google-maps/) library\nis a collection of React components and hooks for the Google Maps JavaScript\nAPI.\n**Important:** The [vis.gl/react-google-maps](https://visgl.github.io/react-google-maps/) library is offered using an open source license. It is not governed by the Google Maps Platform Support Technical Support Services Guidelines, the SLA, or the Deprecation Policy (however, any Google Maps Platform services used by the library remain subject to the Google Maps Platform Terms of Service). If you find a bug, or have a feature request, file an issue on [GitHub](https://github.com/visgl/react-google-maps/issues) . \n\n### TypeScript\n\n```jsx\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { APIProvider, Map } from '@vis.gl/react-google-maps';\n\nconst API_KEY =\n globalThis.GOOGLE_MAPS_API_KEY ?? (\"YOUR_API_KEY\");\n\nconst App = () =\u003e (\n \u003cAPIProvider\n solutionChannel='GMP_devsite_samples_v3_rgmbasicmap'\n apiKey={API_KEY}\u003e\n \u003cMap\n defaultZoom={8}\n defaultCenter={{ lat: -34.397, lng: 150.644 }}\n gestureHandling={'greedy'}\n disableDefaultUI={true}\n /\u003e\n \u003c/APIProvider\u003e\n);\nconst root = createRoot(document.getElementById('app')!);\nroot.render(\u003cApp /\u003e);\n\nexport default App;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/samples/rgm-basic-map/index.tsx#L17-L39\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\n### JavaScript\n\n```javascript\nimport React from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { APIProvider, Map } from \"@vis.gl/react-google-maps\";\nconst API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? \"YOUR_API_KEY\";\nconst App = () =\u003e (\n \u003cAPIProvider\n solutionChannel=\"GMP_devsite_samples_v3_rgmbasicmap\"\n apiKey={API_KEY}\n \u003e\n \u003cMap\n defaultZoom={8}\n defaultCenter={{ lat: -34.397, lng: 150.644 }}\n gestureHandling={\"greedy\"}\n disableDefaultUI={true}\n /\u003e\n \u003c/APIProvider\u003e\n);\nconst root = createRoot(document.getElementById(\"app\"));\n\nroot.render(\u003cApp /\u003e);\nexport default App;https://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/rgm-basic-map/docs/index.jsx#L17-L37\n```\n| **Note:** The JavaScript is compiled from the TypeScript snippet.\n\n### CSS\n\n```css\nbody {\n margin: 0;\n font-family: sans-serif;\n}\n\n#app {\n width: 100vw;\n height: 100vh;\n}\nhttps://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/rgm-basic-map/docs/style.css#L7-L16\n```\n\n### HTML\n\n```html\n\u003chtml\u003e\n \u003chead\u003e\n \u003ctitle\u003eReact Google Maps - Basic Map\u003c/title\u003e\n\n \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"./style.css\" /\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"app\"\u003e\u003c/div\u003e\n \u003cscript type=\"module\" src=\"./index\"\u003e\u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003ehttps://github.com/googlemaps/js-samples/blob/2683f7366fb27829401945d2a7e27d77ed2df8e5/dist/samples/rgm-basic-map/docs/index.html#L8-L18\n```\n\n### Try Sample\n\n[Google Cloud Shell](https://ssh.cloud.google.com/cloudshell/editor?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fgooglemaps%2Fjs-samples&cloudshell_git_branch=sample-rgm-basic-map&cloudshell_tutorial=cloud_shell_instructions.md&cloudshell_workspace=.)\n\n### Clone Sample\n\n\nGit and Node.js are required to run this sample locally. Follow these [instructions](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install Node.js and NPM. The following commands clone, install dependencies and start the sample application. \n\n git clone -b sample-rgm-basic-map https://github.com/googlemaps/js-samples.git\n cd js-samples\n npm i\n npm start\n\n\nOther samples can be tried by switching to any branch beginning with `sample-`\u003cvar translate=\"no\"\u003eSAMPLE_NAME\u003c/var\u003e. \n\n git checkout sample-\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nx\"\u003eSAMPLE_NAME\u003c/span\u003e\u003c/var\u003e\n npm i\n npm start"]]