Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@slorber/react-google-maps

JustFly198476MIT1.4.2TypeScript support: included

React.js Google Maps API integration

React, Google, Google Maps, google maps, google-maps, @google-maps, google-maps-api, @google-maps-api, Map, Maps, API, GoogleMap, react-component, addons/MarkerClusterer, directions/DirectionsRenderer, directions/DirectionsService, drawing/DrawingManager, places/SearchBox, InfoWindow, KmlLayer, Marker, MarkerClusterer, OverlayView, Circle, Polygon, Polyline, Rectangle, StreetViewPanorama, TrafficLayer, visualization/HeatmapLayer, withGoogleMap, ScriptLoader, Typescript

readme

@react-google-maps/api

logo

@react-google-maps/api

This library requires React v16.6 or later. To use the latest features (including hooks) requires React v16.8+. If you need support for earlier versions of React, you should check out react-google-maps

This is complete re-write of the (sadly unmaintained) react-google-maps library. We thank tomchentw for his great work that made possible.

@react-google-maps/api provides very simple bindings to the google maps api and lets you use it in your app as React components.

Here are the main additions to react-google-maps that were the motivation behind this re-write

Install @react-google-maps/api

with NPM

npm i -S @react-google-maps/api

or Yarn

yarn add @react-google-maps/api

Main features

  • Simplified API
  • Uses the new Context API
  • Supports async React (StrictMode complient)
  • Removes lodash dependency => smaller bundle size 12.4kb gzip, tree-shakeable https://bundlephobia.com/result?p=@react-google-maps/api@1.4.0
  • forbids loading of Roboto fonts, if you set property preventGoogleFonts on <LoadScript preventGoogleFonts /> component

Examples

Examples can be found in two places:

  1. Official docs (powered by react-styleguidist.
  2. A Gatsby app including some examples. See the examples folder
  3. Gatsby.js Demo

Advice

Using the examples requires you to generate a google maps api key. For instructions on how to do that please see the following guide

Community Help Resource

You can join the community at https://spectrum.chat/react-google-maps to ask questions and help others with your experience.

Contribute

Maintainers and contributors are very welcome! See this issue to get started.

Migration from react-google-maps@9.4.5

if you need an access to map object, instead of ref prop, you need to use onLoad callback on <GoogleMap /> component.

Before:

// before
<GoogleMap
  ref={map => {
    const bounds = new window.google.maps.LatLngBounds();

    map.fitBounds(bounds);
  }}
/>

After:

<GoogleMap
  onLoad={map => {
    const bounds = new window.google.maps.LatLngBounds();
    map.fitBounds(bounds);
  }}
  onUnmount={map => {
    // do your stuff before map is unmounted
  }}
/>

Since 1.2.0 you can use onLoad and onMount props for each @react-google-maps/api component, ref does not contain API methods anymore.

Since version 1.2.2 We added useGoogleMap hook, which is working only with React@16.8.1 and later versions.

Websites made with @react-google-maps-api

DriveFromTo.com Transfer Booking service PWA.

add your website by making PR!

changelog

Changelog

1.4.2 Fix onOverlayComplete

1.4.0 Added DistanceMatrixService, fixed invariant errors, fixed getPixelPositionOffset in OverlayView, updated @react-google-maps/marker-clusterer@1.4.0

1.2.4 Fixed builds with TSDX

1.2.3 Added MarkerClusterer refactored to typescript.

  • Removed instans persistance feature due to bugs with google-maps-api.

  • UMD and ESM builds

  • Added new onMouseUp and onMouseDown props for <GoogleMap /> component

1.2.2 fix draggable type on Marker, export Types alongside with Components, useGoogleMap hook

1.2.1 fix InfoBox rendering issue

1.2.0 Typescript refactoring

1.1.1-alpha Additional component support

  • StreetViewPanorama
  • StreetViewService
  • MarkerClusterer

1.1.0

  • Re-write in Typescript
  • DEPRECATED: FuctionTablesLayer (was deprecated by google and support will be cut completely on December 3, 2019)

1.0.10 Fix cleanup in <LoadScript />

1.0.9 Fix hanging jest-worker child processes on setInterval

1.0.8 Added StandaloneSearchBox component, update docs and examples

1.0.3 Moved to organization @react-google-maps

Archive

1.0.5

Fixed a bug with <LoadScript language /> prop update and cleanup after unmount

1.0.6

added onUnmount func prop to <LoadScript />

1.0.7

fix memory leak of google-maps-api-v3

1.0.8

added property options to <GoogleMap options={}>

options are consistent with MapOptions Interface