node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »


load-google-maps-api npm Version Build Status

A thin, Promise-returning helper for loading the Google Maps JavaScript API.


const loadGoogleMapsAPI = require('load-google-maps-api')
loadGoogleMapsAPI().then(function(googleMaps) {
  console.log(googleMaps) //=> Object { Animation: Object, ...
}).catch((err) => {

Read the source to understand how this works.

N.B. Just like the Google Maps API itself, this module is client-side only.


Without this module, you would need to specify a named global callback, and pass said callback’s name as a parameter in the script tag’s src. For example:

window.googleMapsOnLoad = () => {
  // `google.maps` available here
<script async defer src=""></script>

This module abstracts this ceremony away, and fits better with Browserify or Webpack.


const loadGoogleMapsAPI = require('load-google-maps-api')


Returns a Promise. (See Usage.)

  • Fulfilled if load was successful. The fulfilled callback is passed the google.maps object.
  • Rejected if we weren’t able to load the Google Maps API after options.timeout.

options is an optional object literal:

Key Description Default
channel Client usage reporting channel undefined
client Client ID undefined
key Your API key undefined
language Language undefined
libraries Supplemental libraries to load []
region Region undefined
timeout Time in milliseconds before rejecting the promise 10000
v API version undefined


Install via yarn:

$ yarn add load-google-maps-api

Or npm:

$ npm install --save load-google-maps-api