@frankhoodbs/gmaps-utils
v4.0.2
Published
Utility for load the Google Maps JS SDK
Keywords
Readme
Gmaps Utils
A lightweight utility based on https://www.npmjs.com/package/@googlemaps/js-api-loader to help initialize Google Maps JavaScript API with ease.
Features
- Simplified Google Maps JavaScript API initialization.
- Supports APIOptions settings (See Doc: https://developers.google.com/maps/documentation/javascript/load-maps-js-api?hl=it#required_parameters).
- Load and use all possible libraries.
Usage
- Import the utility:
import gMapsInit, { clearGMapsCache, type APIOptions } from './path-to-gMapsInit-file';- Initialize Google Maps:
const gmapsOptions: APIOptions = {
key: 'YOUR_API_KEY',
language: 'en', // Optional. Default is 'it'
region: 'US' // Optional. Default is 'IT'
};
gMapsInit(gmapsOptions)
.then((googleMaps) => {
// Google Maps is now initialized and can be used.
const map = new googleMaps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
})
.catch((error) => {
console.error('Error loading Google Maps', error);
});