davidkudera / google-maps-loader

Async loader for google maps api
MIT License
289 stars 61 forks source link

google-maps-loader

Async loader for google maps api written in typescript with promises.

This is an unofficial package first released when there was no official modern loader for google maps. This changed with @googlemaps/js-api-loader which is based on an older version of this package.

Version >= 4.0.0: Typescript definitions are published with this package. Install @types/google-maps for previous versions.

This module does not change original google maps api in any way. It just provide easy way to load and use this API asynchronously.

Browser only!

Installation

$ npm install --save google-maps

or with Pika:

<script type="module">
    import { Loader } from 'https://cdn.pika.dev/google-maps';
    // todo: see docs bellow
</script>

Usage

import {Loader, LoaderOptions} from 'google-maps';
// or const {Loader} = require('google-maps'); without typescript

const options: LoaderOptions = {/* todo */};
const loader = new Loader('my-api-key', options);

const google = await loader.load();
const map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: -34.397, lng: 150.644},
    zoom: 8,
});

Without await/async:

loader.load().then(function (google) {
    const map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: -34.397, lng: 150.644},
        zoom: 8,
    });
});

Options

Changelog list