Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions plugin/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
lib.setOptions({
setOptions({
key: apiKey ?? '',
v: 'weekly',
language,
region,
});

this.gMapsRef = await lib.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;

Expand Down