
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
load-google-maps-api
Advanced tools
A lightweight Promise-returning helper for loading the Google Maps JavaScript API
A lightweight Promise-returning helper for loading the Google Maps JavaScript API
google.maps
objectconst loadGoogleMapsApi = require('load-google-maps-api')
loadGoogleMapsApi().then(function (googleMaps) {
new googleMaps.Map(document.querySelector('.map'), {
center: {
lat: 40.7484405,
lng: -73.9944191
},
zoom: 12
})
}).catch(function (error) {
console.error(error)
})
N.B. Just like the Google Maps API itself, this module is client-side only.
Without this module, you would need to specify a named global callback, and pass said callback’s name as a parameter in the script
tag’s src
. For example:
<script>
window.googleMapsOnLoad = function () {
// `window.google.maps` available here
}
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?callback=googleMapsOnLoad"></script>
This module abstracts this ceremony away, and fits better with modern bundlers like Browserify or Webpack.
const loadGoogleMapsApi = require('load-google-maps-api')
Returns a Promise.
google.maps
object. If loadGoogleMapsApi
is called multiple times on a page, the fulfilled callback will be passed the previously-loaded google.maps
object.options.timeout
.See Usage.
options
is an optional object literal:
Key | Description | Default |
---|---|---|
apiUrl | The Google Maps API script tag URL | 'https://maps.googleapis.com/maps/api/js' |
channel | Client usage reporting channel | undefined |
client | Client ID | undefined |
key | Your API key | undefined |
language | Language | undefined |
libraries | Supplemental libraries to load | [] |
region | Region | undefined |
timeout | Time in milliseconds before rejecting the Promise | 10000 |
v | API version | undefined |
$ yarn add load-google-maps-api
FAQs
A lightweight Promise-returning helper for loading the Google Maps JavaScript API
The npm package load-google-maps-api receives a total of 28,640 weekly downloads. As such, load-google-maps-api popularity was classified as popular.
We found that load-google-maps-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.