@googlemaps/js-api-loader vs react-google-maps vs google-maps-react
Google Maps Integration in React Applications Comparison
3 Years
@googlemaps/js-api-loaderreact-google-mapsgoogle-maps-reactSimilar Packages:
What's 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.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
@googlemaps/js-api-loader1,898,788
409706 kB252 months agoApache-2.0
react-google-maps89,796
4,629-2728 years agoMIT
google-maps-react48,135
1,639-2955 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 Release Stable Tests/Build

codecov semantic-release

Contributors License StackOverflow Discord

Google Maps JavaScript API Loader

Description

Load the Google Maps JavaScript API script dynamically. This takes inspiration from the google-maps npm package but updates it with ES6, Promises, and TypeScript.

Requirements

Installation

Install the @googlemaps/js-api-loader NPM package with:

npm i @googlemaps/js-api-loader

Alternatively you may add the umd package directly to the html document using the unpkg link.

<script src="https://unpkg.com/@googlemaps/js-api-loader@1.x/dist/index.min.js"></script>

When adding via unpkg, the loader can be accessed at google.maps.plugins.loader.Loader.

TypeScript

TypeScript users need to install the following types package.

npm i -D @types/google.maps

Documentation

The reference documentation can be found at this link. The Google Maps JavaScript API documentation is the authoritative source for the loader options.

Usage

import { Loader } from '@googlemaps/js-api-loader';

const loader = new Loader({
  apiKey: "",
  version: "weekly",
  libraries: ["places"]
});

const mapOptions = {
  center: {
    lat: 0,
    lng: 0
  },
  zoom: 4
};

Using a promise for a specific library.

// Promise for a specific library
loader
  .importLibrary('maps')
  .then(({Map}) => {
    new Map(document.getElementById("map"), mapOptions);
  })
  .catch((e) => {
    // do something
  });

Using a promise for when the script has loaded.

// Promise
loader
  .load()
  .then((google) => {
    new google.maps.Map(document.getElementById("map"), mapOptions);
  })
  .catch(e => {
    // do something
  });

Alternatively, if you want to use a callback.

// Callback
loader.loadCallback(e => {
  if (e) {
    console.log(e);
  } else {
    new google.maps.Map(document.getElementById("map"), mapOptions);
  }
});

View the package in action here.

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.

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. Accordingly, while the library is in version 0.x, backwards-incompatible changes may be introduced at any time.

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.