From 9759fd829c9c839290bd8f3581d74db8680ec002 Mon Sep 17 00:00:00 2001 From: Jan Gessinger Date: Tue, 18 Nov 2025 11:51:34 +0100 Subject: [PATCH] feat: Use functional API of @googlemaps/js-api-loader --- plugin/package.json | 2 +- plugin/src/web.ts | 14 ++++++-------- pnpm-lock.yaml | 12 +++++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugin/package.json b/plugin/package.json index 594771e..f3854d9 100644 --- a/plugin/package.json +++ b/plugin/package.json @@ -91,7 +91,7 @@ "access": "public" }, "dependencies": { - "@googlemaps/js-api-loader": "~1.16.8", + "@googlemaps/js-api-loader": "~2.0.2", "@googlemaps/markerclusterer": "~2.5.3", "@types/google.maps": "~3.58.1" } diff --git a/plugin/src/web.ts b/plugin/src/web.ts index aae4773..ef75111 100644 --- a/plugin/src/web.ts +++ b/plugin/src/web.ts @@ -30,6 +30,7 @@ import type { RemovePolylinesArgs, RemoveTileOverlayArgs, } from './implementation'; +import { importLibrary, setOptions } from '@googlemaps/js-api-loader'; export class CapacitorGoogleMapsWeb extends WebPlugin implements CapacitorGoogleMapsPlugin { private gMapsRef: google.maps.MapsLibrary | undefined = undefined; @@ -121,19 +122,16 @@ export class CapacitorGoogleMapsWeb extends WebPlugin implements CapacitorGoogle private async importGoogleLib(apiKey: string, region?: string, language?: string) { if (this.gMapsRef === undefined) { - const lib = await import('@googlemaps/js-api-loader'); - const loader = new lib.Loader({ - apiKey: apiKey ?? '', - version: 'weekly', + setOptions({ + key: apiKey ?? '', + v: 'weekly', language, region, }); - this.gMapsRef = await loader.importLibrary('maps'); + this.gMapsRef = await importLibrary('maps'); // Import marker library once - const { AdvancedMarkerElement, PinElement } = (await google.maps.importLibrary( - 'marker' - )) as google.maps.MarkerLibrary; + const { AdvancedMarkerElement, PinElement } = await importLibrary('marker'); this.AdvancedMarkerElement = AdvancedMarkerElement; this.PinElement = PinElement; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f263a9..0f7ac23 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -157,8 +157,8 @@ importers: plugin: dependencies: '@googlemaps/js-api-loader': - specifier: ~1.16.8 - version: 1.16.10 + specifier: ~2.0.2 + version: 2.0.2 '@googlemaps/markerclusterer': specifier: ~2.5.3 version: 2.5.3 @@ -1116,8 +1116,8 @@ packages: resolution: {integrity: sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} - '@googlemaps/js-api-loader@1.16.10': - resolution: {integrity: sha512-c2erv2k7P2ilYzMmtYcMgAR21AULosQuUHJbStnrvRk2dG93k5cqptDrh9A8p+ZNlyhiqEOgHW7N9PAizdUM7Q==} + '@googlemaps/js-api-loader@2.0.2': + resolution: {integrity: sha512-bKVuTqatS8Jven5aFqVB7rCHF1VFEzpzyi0ruzO0GUR+A7m9oMqMgtnmpANj7kMYEvvhty8Fk7TnJ1MKjWHu+Q==} '@googlemaps/markerclusterer@2.5.3': resolution: {integrity: sha512-x7lX0R5yYOoiNectr10wLgCBasNcXFHiADIBdmn7jQllF2B5ENQw5XtZK+hIw4xnV0Df0xhN4LN98XqA5jaiOw==} @@ -8642,7 +8642,9 @@ snapshots: '@eslint/js@8.57.1': {} - '@googlemaps/js-api-loader@1.16.10': {} + '@googlemaps/js-api-loader@2.0.2': + dependencies: + '@types/google.maps': 3.58.1 '@googlemaps/markerclusterer@2.5.3': dependencies: