@googlemaps/loader
TypeScript icon, indicating that this package has built-in type declarations

0.0.10 • Public • Published

Loader for Google Maps v3

NOTE: This package has been deprecated in favor of @googlemaps/js-api-loader. The interface remains the same.

Description

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

NPM

Available via NPM as the package @googlemaps/loader

Documentation

The reference documentation can be found at this link.

Example

import { Loader } from '@googlemaps/loader';

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

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

Using a promise for when the script has loaded.

// Promise
loader
  .load()
  .then(() => {
    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.

Support

This library is community supported. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it.

If you find a bug, or have a feature suggestion, please log an issue. If you'd like to contribute, please read How to Contribute.

Dependents (3)

Package Sidebar

Install

npm i @googlemaps/loader

Weekly Downloads

217

Version

0.0.10

License

Apache-2.0

Unpacked Size

295 kB

Total Files

34

Last publish

Collaborators

  • wangela
  • google-wombot