Skip to content

Instantly share code, notes, and snippets.

@cassaram09
Created September 13, 2017 21:58
Show Gist options
  • Select an option

  • Save cassaram09/58da6c6658077b1df0319d8519b348c9 to your computer and use it in GitHub Desktop.

Select an option

Save cassaram09/58da6c6658077b1df0319d8519b348c9 to your computer and use it in GitHub Desktop.

Revisions

  1. cassaram09 created this gist Sep 13, 2017.
    25 changes: 25 additions & 0 deletions loadGoogleMaps.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    import load from "little-loader";
    import qs from "query-string";

    // YOUR_API_KEY - string
    // libraries - array of strings, eg ['places']

    const loadGoogleMaps = (YOUR_API_KEY, libraries) => {

    return new Promise( (resolve, reject) => {
    var params = {key: YOUR_API_KEY, libraries: libraries}

    load(`https://maps.googleapis.com/maps/api/js?${qs.stringify(params)}`, (error) => {
    if (error) {
    reject("Unable to load Google Maps");
    } else {
    console.log('Google Maps loaded.')
    resolve();
    }
    })

    })

    }

    export default loadGoogleMaps;