places-autocomplete-svelte
Version:
A flexible, accessible, and secure Svelte component leveraging the Google Maps Places Autocomplete API (New) to provide a user-friendly way to search for and retrieve detailed address information.
35 lines (34 loc) • 1.47 kB
TypeScript
import { type Writable } from 'svelte/store';
import { importLibrary, type APIOptions } from "@googlemaps/js-api-loader";
interface GMapsContext {
isInitialized: Writable<boolean>;
error: Writable<Error | null>;
initializationPromise: Promise<void> | null;
}
export type { GMapsContext, APIOptions };
/**
* Creates and sets the Google Maps context with writable stores.
* This is synchronous and should be called once in a top-level component's script.
*/
export declare function setGMapsContext(): void;
/**
* Retrieves the shared Google Maps context.
* @returns {GMapsContext} The stores for initialization status and errors.
*/
export declare function getGMapsContext(): GMapsContext;
export declare function hasGMapsContext(): boolean;
/**
* Asynchronously initializes the Google Maps loader using the provided context.
* This function is idempotent and safe to be called multiple times.
* @param context - The GMapsContext object.
* @param options - The options for the JS API loader, including your API key.
* @returns {Promise<void>}
*/
export declare function initialiseGMaps(options: APIOptions): Promise<void>;
/**
* Initializes the Google Maps API without using the context.
* @param options The options for the JS API loader, including your API key.
* @returns A promise that resolves when the API is initialized.
*/
export declare function initialiseGMapsNoContext(options: APIOptions): Promise<void>;
export { importLibrary };