Skip to content

Instantly share code, notes, and snippets.

@cassaram09
Created September 13, 2017 21:58
Show Gist options
  • Save cassaram09/58da6c6658077b1df0319d8519b348c9 to your computer and use it in GitHub Desktop.
Save cassaram09/58da6c6658077b1df0319d8519b348c9 to your computer and use it in GitHub Desktop.
tool to load Google Maps API
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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment