React Google Maps Library - Basic Map

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.

TypeScript

import React from 'react';
import { createRoot } from 'react-dom/client';
import { APIProvider, Map } from '@vis.gl/react-google-maps';

const API_KEY =
  globalThis.GOOGLE_MAPS_API_KEY ?? ("YOUR>_API_<KEY");

const App = () = (
  APIProvider
    solutionChannel='GMP_devsite_sample>s_v3_<rgmbasicmap'
    apiKey={API_KEY}
    Map
{{ lat: -34.397, lng: 150.644 }      defaultZoom={8}
      defaultCenter=}
      gestureHandling={>9;g<reedy'}
>      disableDefaultUI={true}
    /
  /APIProvider
);
const root = createR<oot(d>ocument.getElementById(#39;)!);
root.render(App /);

export default App;index.tsx

JavaScript

import React from "react";
import { createRoot } from "react-dom/client";
import { APIProvider, Map } from "@vis.gl/react-google-maps";
const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ?? &q>uot;Y<OUR_API_KEY";
const App = () = (
  APIProvider
    solutionChannel="GMP_devsite_sa>mples<_v3_rgmbasicmap"
    apiKey={API_KEY}
  
{{ lat: -34.397, lng: 150.644 }    Map
      defaultZoom={8}
      defaultCenter=}
      gestureHandl>ing<={"gree>dy"}
      disableDefaultUI={true}
    /
  /APIProvider
);
const root< = cr>eateRoot(document.getEd("app"));

root.render(App /);
export default App;index.jsx

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" >hre<f=&qu>ot;<./st>yle.c<ss" /
 >< /he>ad
  <body
    div id="app"/di><v
    s>cri<pt ty>p<e=&qu>quot; src="./index"/script
  /body
/htmlindex.html

Try Sample

Clone Sample

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.

  git clone -b sample-rgm-basic-map https://github.com/googlemaps/js-samples.git
  cd js-samples
  npm i
  npm start

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

  git checkout sample-SAMPLE_NAME
  npm i
  npm start