From 06cd6a5460438b31b4752d224c56561ebd5b1eb3 Mon Sep 17 00:00:00 2001 From: "jgessinger@aeins.de" Date: Tue, 9 May 2023 08:21:12 +0200 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFfeat(google-maps):=20Added=20ability?= =?UTF-8?q?=20for=20plugin=20to=20take=20already=20instanciated=20google?= =?UTF-8?q?=20maps=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- google-maps/src/web.ts | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) 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'); + } } }