google-places-core
Version:
A lightweight Google Places API logic library.
112 lines (104 loc) • 3.3 kB
TypeScript
interface GooglePlacePredictionT {
place_id: string;
description: string;
structured_formatting: {
main_text: string;
secondary_text: string;
};
types: string[];
}
interface GooglePlaceDetailsT {
geometry: {
location: {
lat: number;
lng: number;
};
viewport?: {
south: number;
west: number;
north: number;
east: number;
};
};
formatted_address: string;
name?: string;
place_id: string;
}
declare global {
interface Window {
google?: GoogleMaps;
}
}
interface GoogleMaps {
maps: {
places: {
AutocompleteService: new () => any;
PlacesService: new (div: HTMLDivElement) => any;
PlacesServiceStatus: {
OK: string;
ZERO_RESULTS: string;
ERROR: string;
[key: string]: string;
};
};
};
}
interface GooglePlacesService {
fetchPredictions(input: string): Promise<GooglePlacePredictionT[]>;
fetchPlaceDetails(placeId: string): Promise<GooglePlaceDetailsT>;
}
interface GooglePlacesManagerState {
predictions: GooglePlacePredictionT[];
isLoading: boolean;
error: Error | null;
}
declare class GooglePlacesManager {
private state;
private subscribers;
private placesService;
private debouncedGetPredictions;
constructor(service: GooglePlacesService, debounceTime?: number);
private setState;
private fetchPredictionsInternal;
updateSearchInput(input: string): void;
getPlaceDetails(placeId: string): Promise<GooglePlaceDetailsT>;
subscribe(callback: (state: GooglePlacesManagerState) => void): () => void;
getState(): GooglePlacesManagerState;
destroy(): void;
}
declare class Helpers {
apiKey: string;
constructor(apiKey: string);
checkBrowserEnvironment(): boolean;
isLoaded(): boolean;
isScriptInjected(): boolean;
injectScript(): Promise<void>;
waitForLoad(): Promise<void>;
}
declare class GooglePlacesWebService extends Helpers implements GooglePlacesService {
private autocompleteService;
private placesService;
private readonly isBrowser;
private loadPromise;
constructor(apiKey: string);
fetchPredictions(input: string): Promise<GooglePlacePredictionT[]>;
fetchPlaceDetails(placeId: string): Promise<GooglePlaceDetailsT>;
private ensureReady;
private loadGoogleMaps;
private getPredictions;
private getPlaceDetails;
private initServices;
private transformPredictions;
private transformPlaceDetails;
}
declare class GooglePlacesNativeService implements GooglePlacesService {
private API_KEY;
constructor(apiKey: string);
fetchPredictions: (input: string) => Promise<GooglePlacePredictionT[]>;
fetchPlaceDetails: (placeId: string) => Promise<GooglePlaceDetailsT>;
}
declare function createGooglePlacesManager(apiKey: string, platform?: 'web' | 'native', options?: {
debounceTime?: number;
}): GooglePlacesManager;
export { GooglePlacesManager, GooglePlacesNativeService, GooglePlacesWebService, createGooglePlacesManager };
export type { GooglePlaceDetailsT, GooglePlacePredictionT, GooglePlacesManagerState };