import { NativeModules, Platform } from 'react-native'; import type { FieldsParam, GeocodingResult, Place, PlacePrediction, PredictionFiltersParam, } from './types'; const LINKING_ERROR = `The package 'react-native-google-places-sdk' doesn't seem to be linked. Make sure: \n\n` + Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n'; const GooglePlacesSdk = NativeModules.GooglePlacesSdk ? NativeModules.GooglePlacesSdk : new Proxy( {}, { get() { throw new Error(LINKING_ERROR); }, } ); export function initialize(apiKey: string) { if (!apiKey) return; GooglePlacesSdk.initialize(apiKey); } export async function fetchPredictions( query: string, filters: PredictionFiltersParam = {} ): Promise { const predictions = await GooglePlacesSdk.fetchPredictions(query, filters); return predictions; } export async function fetchPlaceByID( placeID: string, fields: FieldsParam = [] ): Promise { const place = await GooglePlacesSdk.fetchPlaceByID(placeID, fields); return place; } export async function startNewSession() { const msg = await GooglePlacesSdk.startNewSession(); return msg; } export async function clearSession() { const msg = await GooglePlacesSdk.clearSession(); return msg; } export async function geocode(address: string): Promise { const result = await GooglePlacesSdk.geocode(address); return result; } export async function reverseGeocode( lat: number, lng: number ): Promise { const result = await GooglePlacesSdk.reverseGeocode(lat, lng); return result; }