MCPcopy
hub / github.com/visgl/react-google-maps

github.com/visgl/react-google-maps @v1.9.0 sqlite

repository ↗ · DeepWiki ↗ · release v1.9.0 ↗
522 symbols 1,309 edges 304 files 21 documented · 4%
README

React Components for the Google Maps JavaScript API

MIT License

This is a TypeScript / JavaScript library to integrate the Maps JavaScript API into your React application. It comes with a collection of React components to create maps, markers, infowindows, geometry overlays (circles, polylines, polygons), and photorealistic [3D maps][gmp-maps-3d], as well as a set of hooks to use some of the Maps JavaScript API [Services][gmp-services] and [Libraries][gmp-libraries].

Installation

This library is available on npm as [@vis.gl/react-google-maps][npm-package].

npm install @vis.gl/react-google-maps

or

yarn add @vis.gl/react-google-maps

(PowerShell users: since @ has a special meaning in PowerShell, the package name has to be quoted)

Usage

Import the [APIProvider][api-provider] and wrap it around all components that should have access to the Maps JavaScript API. Any component within the context of the APIProvider can use the hooks and components provided by this library.

To render a simple map, add a [Map][api-map] component inside the APIProvider. Within the Map component, you can then add further components like [Marker][api-marker], [AdvancedMarker][api-adv-marker], [InfoWindow][api-infowindow], or geometry components such as [Circle][api-circle], [Polyline][api-polyline], and [Polygon][api-polygon] to render content on the map. For photorealistic 3D maps, use the [Map3D][api-map-3d] component instead.

For more advanced use-cases you can even add your own components to the map that make use of google.maps.OverlayView or google.maps.WebGlOverlayView.

import {AdvancedMarker, APIProvider, Map} from '@vis.gl/react-google-maps';

function App() {
  const position = {lat: 53.54992, lng: 10.00678};

  return (
    <APIProvider apiKey={'YOUR API KEY HERE'}>
      <Map defaultCenter={position} defaultZoom={10} mapId="DEMO_MAP_ID">
        <AdvancedMarker position={position} />
      </Map>
    </APIProvider>
  );
}

export default App;

Please see our [documentation][docs] or [examples][] for more in-depth information about this library.

Available Components

Component Description
<APIProvider> Loads the Google Maps JavaScript API and provides context.
<Map> Renders a Google Map container and manages the map instance.
<MapControl> Renders custom React components in one of the map's control containers.
<InfoWindow> Displays a standard Google Maps Info Window overlay.
<Marker> Displays a legacy Google Maps marker on the map.
<AdvancedMarker> Renders a highly customizable modern Advanced Marker.
<Pin> Customizes the background, border, and glyph colors of an AdvancedMarker.
<Circle> Draws a circle at a given center and radius on the map.
<Rectangle> Draws a rectangular vector boundary on the map.
<Polyline> Draws a linear path on the map.
<Polygon> Draws a closed polygon boundary on the map.
<StaticMap> Renders a lightweight Google Static Maps API image.
<Map3D> Renders a Next-Generation Photorealistic 3D Google Map.
<Marker3D> Places a 3D object or icon within a Map3D view.
<Popover> Renders an overlay/popup relative to a 3D element or coordinates.

Using other libraries of the Maps JavaScript API

Besides rendering maps, the Maps JavaScript API has a lot of [additional libraries][gmp-libraries] for things like geocoding, routing, the Places API, Street View, and a lot more.

These libraries are not loaded by default, which is why this module provides the [useMapsLibrary()][api-use-lib] hook to handle dynamic loading of additional libraries.

For example, if you just want to use the google.maps.geocoding.Geocoder class in a component and you don't even need a map, it can be implemented like this:

import {useMapsLibrary} from '@vis.gl/react-google-maps';

const MyComponent = () => {
  // useMapsLibrary loads the geocoding library, it might initially return `null`
  // if the library hasn't been loaded. Once loaded, it will return the library
  // object as it would be returned by `await google.maps.importLibrary()`
  const geocodingLib = useMapsLibrary('geocoding');
  const geocoder = useMemo(
    () => geocodingLib && new geocodingLib.Geocoder(),
    [geocodingLib]
  );

  useEffect(() => {
    if (!geocoder) return;

    // now you can use `geocoder.geocode(...)` here
  }, [geocoder]);

  return <></>;
};

const App = () => {
  return (
    <APIProvider apiKey={'YOUR API KEY HERE'}>
      <MyComponent />
    </APIProvider>
  );
};

Using Custom Elements of the Maps JavaScript API

The maps JavaScript API also provides a lot of custom elements like the [Places UI Kit][gmp-places-ui-kit] or the [Maps 3D][gmp-maps-3d] elements. This library provides the types needed to use these custom elements in a TypeScript / React application.

import {useMapsLibrary} from '@vis.gl/react-google-maps';

const My3DMap = (props: My3DMapProps) => {
  useMapsLibrary('maps3d');

  const {center, heading, tilt, range, roll} = props;

  return (
    <>
      <gmp-map-3d
        center={center}
        range={range}
        heading={heading}
        tilt={tilt}
        roll={roll}
        mode="SATELLITE"></gmp-map-3d>
    </>
  );
};

Available Custom Elements

Custom Element Description
<gmp-map> The native, web-component-based core 2D vector or raster map element.
<gmp-map-3d> The foundational web component initializing Google's photorealistic 3D globe view.
<gmp-flattener> Flattens a designated region of the 3D terrain mesh for clean placement of shapes or markers.
<gmp-popover> An info-window style popup interface container optimized for positioning inside 3D viewports.
<gmp-advanced-marker> A highly performance-optimized 2D map marker backing custom HTML, asset styling, and pin configurations.
<gmp-marker> A standard billboard/sprite point asset mapped specifically within a 3D globe environment.
<gmp-marker-interactive> An interactive variation of the standard 3D map marker designed to handle user click events and trigger popovers.
<gmp-marker-3d> A volumetric, structural 3D point graphic supporting model scaling, extrusion, and altitude configurations.
<gmp-marker-3d-interactive> An interactive version of the 3D volumetric point graphic that responds to pointer inputs.
<gmp-model-3d> Renders and animates photorealistic native 3D mesh assets (such as glTF models) directly onto map coordinates.
<gmp-model-3d-interactive> An interactive version of the native 3D mesh wrapper enabling pointer events directly on the object surface.
<gmp-polyline-3d> Draws continuous multi-segment line paths across 3D spaces, complete with altitude properties and occlusion toggles.
<gmp-polyline-3d-interactive> An interactive line-string path that listens for clicks and user interactions within the 3D view.
<gmp-polygon-3d> Defines multi-coordinate geometric shapes and boundaries supporting geometric fills and extrusion on the 3D globe.
<gmp-polygon-3d-interactive> An interactive geometric area overlay allowing users to trigger events by interacting with the 3D polygon.
<gmp-circle-path> Generates and draws procedural circular spline layout paths mapped cleanly within 3D environments.
<gmp-route-3d> Overlays and visualizes complex directional pathways, multi-modal steps, and routing telemetry on 3D viewports.
<gmp-air-quality-meter> An environmental monitoring panel displaying localized real-time air safety indices and language-localized parameters.
<gmp-place-autocomplete> A rich UI text input component packing fully automated address lookups and drop-down prediction items.
<gmp-basic-place-autocomplete> A streamlined, lightweight variant of the predictive place autocomplete input widget.
<gmp-place-search> A dynamic local directory UI component that outputs and arranges keyword and vicinity query listings.
<gmp-place-details> A dense, modular location profile card showing media, business stats, scheduling charts, and contact datasets. Layout block styling and structure can be fine-tuned internally using individual child components.
<gmp-place-details-compact> A responsive, space-conscious version of the comprehensive details card tailored for mobile viewports and tooltips.
<gmp-place-details-place-request> An API context bridge element used inside a details panel to tie lookups to an explicit programmatic Google Place ID.
<gmp-place-details-location-request> An API context bridge element used inside a details panel to tie lookups to explicit latitude/longitude coordinates.
<gmp-place-contextual> Handles the presentation of embedded context layers and metadata driven by localized contextual token validation.
<gmp-place-contextual-list-config> Exposes layout configuration rules to change styling distributions and list configurations of local context sheets.
<gmp-place-nearby-search-request> A declarative widget component used to trigger and configure vicinity-focused radial place queries.
<gmp-place-text-search-request> A declarative widget component used to structure and trigger string/text-based global search parameters.

Examples

Explore our examples directory on GitHub or the [examples

Extension points exported contracts — how you extend this code

IntrinsicElements (Interface)
(no doc)
types/react-custom-element-bridge/index.d.ts
Marker3DContextValue (Interface)
(no doc)
src/components/marker-3d.tsx
PointGeometry (Interface)
(no doc)
src/hooks/use-supercluster-worker.ts
Future (Interface)
(no doc)
examples/remix/vite.config.ts
IntrinsicElements (Interface)
(no doc)
examples/map-3d-routes-widget/src/app.tsx
Props (Interface)
(no doc)
examples/drawing/src/undo-redo-control.tsx
PlaceDetailsMarkerProps (Interface)
(no doc)
examples/places-ui-kit/src/place-details-marker.tsx
Props (Interface)
(no doc)
examples/autocomplete/src/autocomplete-result.tsx

Core symbols most depended-on inside this repo

useMapsEventListener
called by 32
src/hooks/use-maps-event-listener.ts
useMap
called by 30
src/hooks/use-map.ts
useMapsLibrary
called by 27
src/hooks/use-maps-library.ts
push
called by 21
src/components/map/use-map-instance.ts
initialize
called by 20
examples/terra-draw/src/use-terra-draw.ts
createStaticMapsUrl
called by 19
src/libraries/create-static-maps-url/index.ts
usePropBinding
called by 18
src/hooks/use-prop-binding.ts
usePropBinding
called by 15
examples/places-ui-kit/src/utility-hooks.ts

Shape

Function 388
Interface 57
Class 44
Method 32
Enum 1

Languages

TypeScript100%

Modules by API surface

src/components/__tests__/__utils__/map-3d-mocks.ts21 symbols
examples/drawing/src/types.ts17 symbols
src/components/api-provider.tsx14 symbols
src/components/map-3d/use-map-3d-events.ts12 symbols
examples/drawing/src/undo-redo.ts9 symbols
src/hooks/use-supercluster-worker.ts8 symbols
examples/worker-marker-clustering/src/hooks/use-supercluster-worker.ts8 symbols
examples/drawing/src/use-drawing-manager.tsx8 symbols
src/libraries/lat-lng-utils.ts7 symbols
src/components/advanced-marker.tsx7 symbols
examples/remix/app/entry.server.tsx7 symbols
src/components/map/use-map-instance.ts6 symbols

Dependencies from manifests, versioned

@deck.gl/aggregation-layers9.3.3 · 1×
@deck.gl/google-maps9.3.3 · 1×
@docusaurus/core3.10.1 · 1×
@docusaurus/plugin-content-docs3.10.1 · 1×
@docusaurus/preset-classic3.10.1 · 1×
@easyops-cn/docusaurus-search-local0.55.2 · 1×
@eslint/js9.17.0 · 1×
@googlemaps/extended-component-library0.6.11 · 1×
@googlemaps/jest-mocks2.18.0 · 1×
@googlemaps/js-api-loader2.0.2 · 1×
@googlemaps/markerclusterer2.5.1 · 1×
@googlemaps/react-wrapper1.1.42 · 1×

For agents

$ claude mcp add react-google-maps \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact