@googlemaps/js-api-loader vs react-google-maps vs google-maps-react
Google Maps Integration in React Applications
@googlemaps/js-api-loaderreact-google-mapsgoogle-maps-reactSimilar Packages:
Google Maps Integration in React Applications

Google Maps Integration in React Applications refers to the process of embedding Google Maps into React-based web applications. This integration allows developers to leverage Google Maps' powerful mapping features, such as displaying maps, adding markers, creating custom overlays, and implementing geolocation functionalities, all within a React component architecture. By using specialized libraries or APIs, developers can easily incorporate interactive and dynamic maps into their applications, enhancing user experience and providing location-based services.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
@googlemaps/js-api-loader2,339,87542462.1 kB622 days agoApache-2.0
react-google-maps199,7714,627-2738 years agoMIT
google-maps-react46,7391,640-2936 years agoMIT
Feature Comparison: @googlemaps/js-api-loader vs react-google-maps vs google-maps-react

API Loading

  • @googlemaps/js-api-loader:

    @googlemaps/js-api-loader provides a simple and efficient way to load the Google Maps JavaScript API on demand. It allows you to specify the API version, libraries, and even use multiple instances of the API, which is great for applications that need to load the API conditionally or in different parts of the app.

  • react-google-maps:

    react-google-maps requires you to load the Google Maps API separately, giving you full control over how and when the API is loaded. This approach allows for greater flexibility and optimization, especially in large applications where you might want to load the API only when needed.

  • google-maps-react:

    google-maps-react handles the loading of the Google Maps API automatically when you use its components. This makes it easy to get started, but it doesn’t offer much flexibility in terms of loading different API versions or libraries. It’s a more opinionated approach that works well for most use cases but may not suit all projects.

Customization

  • @googlemaps/js-api-loader:

    @googlemaps/js-api-loader is focused on loading the Google Maps API and does not provide any UI components or customization options for the map itself. It is a lightweight solution that allows developers to implement their own map components and customize them as needed.

  • react-google-maps:

    react-google-maps provides the most flexibility for customization, as it is built around the concept of higher-order components. This allows developers to create highly customized map components and integrate them with the Google Maps API in a more granular way.

  • google-maps-react:

    google-maps-react offers a good level of customization for its components, including markers, info windows, and map styles. However, it is somewhat limited by the pre-built nature of the components, which may not allow for deep customization in all areas.

Documentation and Community

  • @googlemaps/js-api-loader:

    @googlemaps/js-api-loader has clear and concise documentation, especially for loading the API and managing multiple instances. However, as a relatively new package, its community is still growing, and there may be fewer third-party resources available.

  • react-google-maps:

    react-google-maps also has good documentation, particularly for its HOC-based approach to map integration. The community is active, and there are many examples available, but it may not be as large as the one for google-maps-react.

  • google-maps-react:

    google-maps-react has extensive documentation and a large community of users, which makes it easy to find examples, tutorials, and support. The library has been around for a while, and its popularity means that many common issues have already been addressed by the community.

Ease of Use: Code Examples

  • @googlemaps/js-api-loader:

    Loading the Google Maps API with @googlemaps/js-api-loader

    import { Loader } from '@googlemaps/js-api-loader';
    
    const loader = new Loader({
      apiKey: 'YOUR_API_KEY',
      version: 'weekly',
      libraries: ['places'], // Optional
    });
    
    loader.load().then(() => {
      const map = new google.maps.Map(document.getElementById('map'), {
        center: { lat: -34.397, lng: 150.644 },
        zoom: 8,
      });
    });
    
  • react-google-maps:

    Creating a Map with react-google-maps

    import React from 'react';
    import { withGoogleMap, GoogleMap, Marker } from 'react-google-maps';
    
    const MyMapComponent = withGoogleMap(() => (
      <GoogleMap
        defaultZoom={8}
        defaultCenter={{ lat: -34.397, lng: 150.644 }}
      >
        <Marker position={{ lat: -34.397, lng: 150.644 }} />
      </GoogleMap>
    ));
    
    const App = () => (
      <MyMapComponent
        containerElement={<div style={{ height: '400px' }} />}
        mapElement={<div style={{ height: '100%' }} />}
      />
    );
    
    export default App;
    
  • google-maps-react:

    Using google-maps-react to Create a Simple Map

    import React from 'react';
    import { GoogleApiWrapper, Map, Marker } from 'google-maps-react';
    
    const MapContainer = (props) => {
      return (
        <Map
          google={props.google}
          zoom={8}
          initialCenter={{ lat: -34.397, lng: 150.644 }}
        >
          <Marker position={{ lat: -34.397, lng: 150.644 }} />
        </Map>
      );
    };
    
    export default GoogleApiWrapper({
      apiKey: 'YOUR_API_KEY',
    })(MapContainer);
    
How to Choose: @googlemaps/js-api-loader vs react-google-maps vs google-maps-react
  • @googlemaps/js-api-loader:

    Choose @googlemaps/js-api-loader if you need a lightweight and efficient solution for loading the Google Maps JavaScript API. It is ideal for projects where you want to have fine control over when and how the API is loaded, and it supports multiple instances of the API, making it versatile for various use cases.

  • react-google-maps:

    Choose react-google-maps if you prefer a more flexible and customizable approach to integrating Google Maps in your React application. This library provides a set of higher-order components (HOCs) that allow you to create your own map components with greater control over their behavior and appearance, making it ideal for projects that require extensive customization.

  • google-maps-react:

    Choose google-maps-react if you are building a React application that requires a comprehensive set of pre-built components for Google Maps. This library is suitable for projects that need quick integration with features like markers, info windows, and event handling, all wrapped in easy-to-use React components.

README for @googlemaps/js-api-loader

npm License Stable Tests/Build codecov StackOverflow Discord

Google Maps JavaScript API Loader

Description

Load the Google Maps JavaScript API script dynamically. This is an npm version of the Dynamic Library Import script.

Requirements

Installation

Install @googlemaps/js-api-loader with:

npm install --save @googlemaps/js-api-loader

# or
yarn add @googlemaps/js-api-loader

# or
pnpm add @googlemaps/js-api-loader

TypeScript users should additionally install the types for the Google Maps JavaScript API:

npm install --save-dev @types/google.maps

Usage

import { setOptions, importLibrary } from "@googlemaps/js-api-loader";

// Set the options for loading the API.
setOptions({ key: "your-api-key-here" });

// Load the needed APIs.
// Note: once the returned promise is fulfilled, the libraries are also
//       available in the global `google.maps` namespace.
const { Map } = await importLibrary("maps");
const map = new Map(mapEl, mapOptions);

// Alternatively:
await importLibrary("maps");
const map = new google.maps.Map(mapEl, mapOptions);

// Or, if you prefer using callbacks instead of async/await:
importLibrary("maps").then(({ Map }) => {
  const map = new Map(mapEl, mapOptions);
});

If you use custom HTML elements from the Google Maps JavaScript API (e.g. <gmp-map>, and <gmp-advanced-marker>), you need to import them as well. Note that you do not need to await the result of importLibrary() in this case. The custom elements will upgrade automatically once the library is loaded and you can use the whenDefined() method to wait for the upgrade to complete.

import { setOptions, importLibrary } from "@googlemaps/js-api-loader";

// Set the options for loading the API.
setOptions({ key: "your-api-key-here" });

// Start loading the libraries needed for custom elements.
importLibrary("maps"); // needed for <gmp-map>
importLibrary("marker"); // needed for <gmp-advanced-marker>

// Wait for gmp-map to be upgraded and interact with it.
await customElements.whenDefined("gmp-map");
const map = document.querySelector("gmp-map");
// ...

Documentation

This package exports just two functions, setOptions() and importLibrary().

// Using named exports:
import { setOptions, importLibrary } from "@googlemaps/js-api-loader";

setOptions({ key: GOOGLE_MAPS_API_KEY });
await importLibrary("core");

setOptions(options: APIOptions): void

Sets the options for loading the Google Maps JavaScript API and installs the global google.maps.importLibrary() function that is used by the importLibrary() function of this package.

This function should be called as early as possible in your application and should only be called once. Any further calls will not have any effect and log a warning to the console.

Below is a short summary of the accepted options, see the documentation for full descriptions and additional information:

  • key: string: Your API key. This is the only required option.
  • v: string: The version of the Maps JavaScript API to load.
  • language: string: The language to use.
  • region: string: The region code to use.
  • libraries: string[]: Additional libraries to preload.
  • authReferrerPolicy: string: Set the referrer policy for the API requests.
  • mapIds: string[]: An array of map IDs to preload.
  • channel: string: Can be used to track your usage.
  • solutionChannel: string: Used by the Google Maps Platform to track adoption and usage of examples and solutions.

importLibrary(library: string): Promise

Loads the specified library. Returns a promise that resolves with the library object when the library is loaded. In case of an error while loading the library (might be due to poor network conditions and other unforseeable circumstances), the promise is rejected with an error.

Calling this function for the first time will trigger loading the Google Maps JavaScript API itself.

The following libraries are available:

Migrating from v1 to v2

See the migration guide.

Contributing

Contributions are welcome and encouraged! If you'd like to contribute, send us a pull request and refer to our code of conduct and contributing guide.

Terms of Service

This library uses Google Maps Platform services. Use of Google Maps Platform services through this library is subject to the Google Maps Platform Terms of Service.

This library is not a Google Maps Platform Core Service. Therefore, the Google Maps Platform Terms of Service (e.g. Technical Support Services, Service Level Agreements, and Deprecation Policy) do not apply to the code in this library.

European Economic Area (EEA) developers

If your billing address is in the European Economic Area, effective on 8 July 2025, the Google Maps Platform EEA Terms of Service will apply to your use of the Services. Functionality varies by region. Learn more.

Support

This library is offered via 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.

This library adheres to semantic versioning to indicate when backwards-incompatible changes are introduced.

If you find a bug, or have a feature request, please file an issue on GitHub. If you would like to get answers to technical questions from other Google Maps Platform developers, ask through one of our developer community channels. If you'd like to contribute, please check the contributing guide.

You can also discuss this library on our Discord server.