Updates Oct 6, 2019: The example code is still working well, I have just updated them to use non-decorator syntax.


This is what I make it worked in my recent project. I used react-async-script-loader component.

import React from 'react';
import scriptLoader from 'react-async-script-loader';

class Maps extends React.Component {
  constructor(props) {
    super(props);
    this.map = null;
  }

  componentWillReceiveProps({ isScriptLoaded, isScriptLoadSucceed }) {
    if (isScriptLoaded && !this.props.isScriptLoaded) {
      // load finished
      if (isScriptLoadSucceed) {
        this.map = new google.maps.Map(this.refs.map, {
          center: { lat: 10.794234, lng: 106.706541 },
          zoom: 20
        });

        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(
            position => {
              const pos = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
              };

              this.map.setCenter(pos);

              const marker = new google.maps.Marker({
                position: pos,
                map: this.map,
                title: 'Hello World!'
              });
            },
            () => {
              console.log('navigator disabled');
            }
          );
        } else {
          // Browser doesn't support Geolocation
          console.log('navigator disabled');
        }
      } else this.props.onError();
    }
  }

  render() {
    return (
      <div>
        <div ref="map" style={{ height: '80%', width: '100%' }}></div>
        {!this.map && <div className="center-md">Loading...</div>}
      </div>
    );
  }
}

export default scriptLoader(['https://maps.googleapis.com/maps/api/js?key=API_KEY'])(Maps);
Answer from Thanh Nguyen on Stack Overflow
🌐
Google
developers.google.com › google maps platform › web › maps javascript api › add a google map to a react app
Add a Google map to a React app | Maps JavaScript API | Google for Developers
You learn how to get set up, load the Maps JavaScript API, display your first map, work with markers and marker clustering, draw on the map, and handle user interaction. Note: vis.gl/react-google-map uses Google Maps Platform services. Use of Google Maps Platform services through this library ...
🌐
React Map GL
visgl.github.io › react-google-maps
Home | React Google Maps
Use a Google map as a fully controlled reactive component and use all the other features of the Google Maps JavaScript API.
🌐
Google Maps Platform
mapsplatform.google.com › resources › blog › introducing-react-components-for-the-maps-javascript-api
Blog: Introducing React components for the Maps JavaScript API – Google Maps Platform
Building off of that initial support, today we’re announcing the alpha release of @vis.gl/react-google-maps, the first Google-sponsored library for integrating Maps JavaScript API components in a React web app.
🌐
npm
npmjs.com › package › @react-google-maps › api
react-google-maps/api
React.js Google Maps API integration. Latest version: 2.20.8, last published: 7 days ago. Start using @react-google-maps/api in your project by running `npm i @react-google-maps/api`. There are 495 other projects in the npm registry using @react-google-maps/api.
      » npm install @react-google-maps/api
    
Published   Dec 16, 2025
Version   2.20.8
Author   Alexey Lyakhov
🌐
Google
developers.google.com › google maps platform › web › maps javascript api › react google maps library - basic map
React Google Maps Library - Basic Map | Maps JavaScript API | Google for Developers
"YOUR_API_KEY"; const App = () => ( <APIProvider solutionChannel="GMP_devsite_samples_v3_rgmbasicmap" apiKey={API_KEY} > <Map defaultZoom={8} defaultCenter={{ lat: -34.397, lng: 150.644 }} gestureHandling={"greedy"} disableDefaultUI={true} /> </APIProvider> ); const root = createRoot(document.getElementById("app")); root.render(<App />); export default App; ... Note: The JavaScript is compiled from the TypeScript snippet. body { margin: 0; font-family: sans-serif; } #app { width: 100vw; height: 100vh; } ... <html> <head> <title>React Google Maps - Basic Map</title> <link rel="stylesheet" type="text/css" href="./style.css" /> </head> <body> <div id="app"></div> <script type="module" src="./index"></script> </body> </html>
🌐
GitHub
github.com › visgl › react-google-maps
GitHub - visgl/react-google-maps: React components and hooks for the Google Maps JavaScript API
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 and infowindows, and a set of hooks to use some of the Maps JavaScript ...
Starred by 1.8K users
Forked by 179 users
Languages   TypeScript 86.4% | JavaScript 11.0% | MDX 1.1%
🌐
Google Maps Platform
mapsplatform.google.com › resources › blog › streamline-the-use-of-the-maps-javascript-api-within-your-react-applications
Blog: Streamline the use of the Maps JavaScript API within your React applications – Google Maps Platform
Google Maps Platform and the vis.gl team are proud to announce the official 1.0 release of @vis.gl/react-google-maps, a powerful React integration library designed to streamline the use of the Maps JavaScript API within your React applications.
Find elsewhere
🌐
React Map GL
visgl.github.io › interacting with the google maps javascript api
Interacting with the Google Maps JavaScript API | React Google Maps
import React from 'react'; import ... </Map> </APIProvider> ); }; export default App; The Maps JavaScript API has a lot of additional libraries for things like geocoding, routing, the Places API, Street View, and a lot more....
Top answer
1 of 4
17

Updates Oct 6, 2019: The example code is still working well, I have just updated them to use non-decorator syntax.


This is what I make it worked in my recent project. I used react-async-script-loader component.

import React from 'react';
import scriptLoader from 'react-async-script-loader';

class Maps extends React.Component {
  constructor(props) {
    super(props);
    this.map = null;
  }

  componentWillReceiveProps({ isScriptLoaded, isScriptLoadSucceed }) {
    if (isScriptLoaded && !this.props.isScriptLoaded) {
      // load finished
      if (isScriptLoadSucceed) {
        this.map = new google.maps.Map(this.refs.map, {
          center: { lat: 10.794234, lng: 106.706541 },
          zoom: 20
        });

        if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(
            position => {
              const pos = {
                lat: position.coords.latitude,
                lng: position.coords.longitude
              };

              this.map.setCenter(pos);

              const marker = new google.maps.Marker({
                position: pos,
                map: this.map,
                title: 'Hello World!'
              });
            },
            () => {
              console.log('navigator disabled');
            }
          );
        } else {
          // Browser doesn't support Geolocation
          console.log('navigator disabled');
        }
      } else this.props.onError();
    }
  }

  render() {
    return (
      <div>
        <div ref="map" style={{ height: '80%', width: '100%' }}></div>
        {!this.map && <div className="center-md">Loading...</div>}
      </div>
    );
  }
}

export default scriptLoader(['https://maps.googleapis.com/maps/api/js?key=API_KEY'])(Maps);
2 of 4
12

Thanks Nguyen Thanh. As google now in global scope I used window.google.

import React, { Component } from 'react';
import scriptLoader from 'react-async-script-loader';
class Map extends Component{
    constructor(props) {
        super(props);
    }
    componentWillReceiveProps({isScriptLoadSucceed}){
        if (isScriptLoadSucceed) {
            var markers = [];

            var map = new window.google.maps.Map(document.getElementById('map'), {
                zoom: 12,
                center: {lat: 37.7749300, lng: -122.4194200}
            });
        }
        else{
            alert("script not loaded")
        }
    }

    render(){
        return(
            <div>
                <div id="map" style={{height: "600px"}}></div>
            </div>
        )
    }
}

export default scriptLoader(
    ["https://maps.googleapis.com/maps/api/js?key= APIKEY"]
)(Map)

With react hook we can also load external script

https://usehooks.com/useScript/

//useScript custom hooks from the site

let cachedScripts = [];

function useScript(src) {
  // Keeping track of script loaded and error state

  const [state, setState] = useState({
    loaded: false,
    error: false
  });

  useEffect(
    () => {
      // If cachedScripts array already includes src that means another instance ...
      // ... of this hook already loaded this script, so no need to load again.
      if (cachedScripts.includes(src)) {
        setState({
          loaded: true,

          error: false
        });
      } else {
        cachedScripts.push(src);
        // Create script
        let script = document.createElement("script");
        script.src = src;
        script.async = true;
        // Script event listener callbacks for load and error
        const onScriptLoad = () => {
          setState({
            loaded: true,
            error: false
          });
        };

        const onScriptError = () => {
          // Remove from cachedScripts we can try loading again
          const index = cachedScripts.indexOf(src);
          if (index >= 0) cachedScripts.splice(index, 1);
          script.remove();
          setState({
            loaded: true,
            error: true
          });
        };
        script.addEventListener("load", onScriptLoad);
        script.addEventListener("error", onScriptError);
        // Add script to document body
        document.body.appendChild(script);
        // Remove event listeners on cleanup
        return () => {
          script.removeEventListener("load", onScriptLoad);
          script.removeEventListener("error", onScriptError);
        };
      }
    },
    [src] // Only re-run effect if script src changes
  );
  return [state.loaded, state.error];
}


Usage

//App.js
import React from "react";
import ReactDOM from "react-dom";
import { useState, useEffect } from "react";
function App() {
  const [loaded, error] = useScript(
    "https://maps.googleapis.com/maps/api/js?key=API_KEY"
  );
  useEffect(() => {
    if (loaded) {
      new window.google.maps.Map(document.getElementById("map"), {
        zoom: 12,
        center: { lat: 37.77493, lng: -122.41942 }
      });
    }
  }, [loaded]);

  return (
    <div>
      <div>
        Script loaded: <b>{loaded.toString()}</b>
      </div>
      <div id="map" style={{ height: "600px" }} />
    </div>
  );
}
🌐
Google
developers.google.com › google maps platform › web › maps javascript api › react google maps library - place autocomplete
React Google Maps Library - Place Autocomplete | Maps JavaScript API | Google for Developers
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). If you find a bug, or have a feature request, file an issue on GitHub . import React, { useState, useEffect, useRef } from 'react'; import { createRoot } from 'react-dom/client'; import { APIProvider, ControlPosition, MapControl, AdvancedMarker, Map, useMap, useMapsLibrary, useAdvancedMarkerRef, AdvancedMarkerRef } from '@vis.gl/react-google-maps'; const API_KEY = globalThis.GOOGLE_MAPS_API_KEY ??
🌐
Reddit
reddit.com › r/reactjs › free alternative to google maps js api in react?
r/reactjs on Reddit: Free alternative to Google Maps JS API in React?
June 20, 2025 -

Hey!
I’m learning the MERN stack on Udemy and currently working with React. For a project, I need to use Google Maps JavaScript API to show a map with markers — but it requires billing, which I can't afford right now.

Are there any free and easy-to-use alternatives that work well with React? Mainly need basic map display and markers.

Thanks in advance!

🌐
React Map GL
visgl.github.io › introduction
Introduction | React Google Maps
@vis.gl/react-google-maps provides a reactive wrapper for the Google Maps JavaScript API while still leaving the map instance in charge of state updates.
🌐
React Map GL
visgl.github.io › component
<APIProvider> Component | React Google Maps
The APIProvider is our component to load the Google Maps JavaScript API.
🌐
DEV Community
dev.to › aneeqakhan › how-to-add-google-maps-to-your-web-app-using-react-3c3e
How to Add Google Maps to Your Web App Using React - DEV Community
April 16, 2024 - Once you have your API key, install the @react-google-maps/api package, which provides a React-friendly wrapper for the Google Maps JavaScript API.In your React component, import the necessary modules from @react-google-maps/api and create a ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-integrate-the-google-maps-api-into-react-applications
How to Integrate the Google Maps API into React Applications | DigitalOcean
September 11, 2020 - Hey everyone, I thought going forward you all should know that this library is no longer maintained. The last update was more than 3 years ago. I suggest using react=google-maps/api
🌐
npm
npmjs.com › package › google-map-react
google-map-react - npm
google-map-react is a component written over a small set of the Google Maps API. It allows you to render any React component on the Google Map. It is fully isomorphic and can render on a server.
      » npm install google-map-react
    
Published   May 23, 2025
Version   2.2.5
Author   istarkov https://github.com/istarkov
🌐
Google Maps Platform
mapsplatform.google.com › resources › blog › google-maps-platform-graduates-react-integration-library-to-1-0
Blog: Google Maps Platform Graduates React Integration Library to 1.0 – Google Maps Platform
React Integration: Incorporate elements from the Maps JavaScript API as React components for an intuitive development experience, complete with state management and hooks to access the underlying Map instance.
🌐
GitHub
github.com › googlemaps › react-wrapper
GitHub - googlemaps/react-wrapper: Wrap React components with this libary to load the Google Maps JavaScript API.
import {Wrapper} from '@googlemaps/react-wrapper'; const MyApp = () => ( <Wrapper apiKey={'YOUR_API_KEY'}> <MyMapComponent /> </Wrapper> ); The preceding example will not render any elements unless the Google Maps JavaScript API is successfully loaded.
Starred by 381 users
Forked by 54 users
Languages   TypeScript 55.9% | JavaScript 44.1%