Skip to content

Commit 9759fd8

Browse files
committed
feat: Use functional API of @googlemaps/js-api-loader
1 parent 81caaaf commit 9759fd8

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"access": "public"
9292
},
9393
"dependencies": {
94-
"@googlemaps/js-api-loader": "~1.16.8",
94+
"@googlemaps/js-api-loader": "~2.0.2",
9595
"@googlemaps/markerclusterer": "~2.5.3",
9696
"@types/google.maps": "~3.58.1"
9797
}

plugin/src/web.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import type {
3030
RemovePolylinesArgs,
3131
RemoveTileOverlayArgs,
3232
} from './implementation';
33+
import { importLibrary, setOptions } from '@googlemaps/js-api-loader';
3334

3435
export class CapacitorGoogleMapsWeb extends WebPlugin implements CapacitorGoogleMapsPlugin {
3536
private gMapsRef: google.maps.MapsLibrary | undefined = undefined;
@@ -121,19 +122,16 @@ export class CapacitorGoogleMapsWeb extends WebPlugin implements CapacitorGoogle
121122

122123
private async importGoogleLib(apiKey: string, region?: string, language?: string) {
123124
if (this.gMapsRef === undefined) {
124-
const lib = await import('@googlemaps/js-api-loader');
125-
const loader = new lib.Loader({
126-
apiKey: apiKey ?? '',
127-
version: 'weekly',
125+
setOptions({
126+
key: apiKey ?? '',
127+
v: 'weekly',
128128
language,
129129
region,
130130
});
131-
this.gMapsRef = await loader.importLibrary('maps');
131+
this.gMapsRef = await importLibrary('maps');
132132

133133
// Import marker library once
134-
const { AdvancedMarkerElement, PinElement } = (await google.maps.importLibrary(
135-
'marker'
136-
)) as google.maps.MarkerLibrary;
134+
const { AdvancedMarkerElement, PinElement } = await importLibrary('marker');
137135
this.AdvancedMarkerElement = AdvancedMarkerElement;
138136
this.PinElement = PinElement;
139137

pnpm-lock.yaml

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)