diff --git a/google-maps/src/web.ts b/google-maps/src/web.ts index e6a45f2ce4..058e9290b4 100644 --- a/google-maps/src/web.ts +++ b/google-maps/src/web.ts @@ -124,17 +124,22 @@ export class CapacitorGoogleMapsWeb language?: string, ) { if (this.gMapsRef === undefined) { - const lib = await import('@googlemaps/js-api-loader'); - const loader = new lib.Loader({ - apiKey: apiKey ?? '', - version: 'weekly', - libraries: ['places'], - language, - region, - }); - const google = await loader.load(); - this.gMapsRef = google.maps; - console.log('Loaded google maps API'); + if (!window.google.maps) { + const lib = await import('@googlemaps/js-api-loader'); + const loader = new lib.Loader({ + apiKey: apiKey ?? '', + version: 'weekly', + libraries: ['places'], + language, + region, + }); + const google = await loader.load(); + this.gMapsRef = google.maps; + console.log('Loaded google maps API'); + } else { + this.gMapsRef = window.google.maps; + console.log('Google maps API already loaded'); + } } }