GithubHelp home page GithubHelp logo

main-kun / js-api-loader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from googlemaps/js-api-loader

0.0 0.0 0.0 9.82 MB

Load the Google Maps JavaScript API script dynamically.

License: Apache License 2.0

HTML 2.83% TypeScript 85.11% JavaScript 12.06%

js-api-loader's Introduction

Google Maps JavaScript API Loader

npm Build Release codecov GitHub contributors semantic-release Discord

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.

Install

Available via npm as the package @googlemaps/js-api-loader.

npm i @googlemaps/js-api-loader

or

yarn add @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/[email protected]/dist/index.min.js"></script>

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

Documentation

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

Example

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 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.

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.

js-api-loader's People

Contributors

dependabot[bot] avatar jpoehnelt avatar semantic-release-bot avatar louisnow avatar googlemaps-bot avatar mkman avatar ronnelsantiago avatar shuuji3 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.