An update of react-native-google-places library, brings compatibility with newer React Native version (0.71.x). It addresses dependency and compatibility issues, ensuring seamless integration with Google Places API for React Native projects.
npm install react-native-google-places-compat
Start by initializing the Google Places client with your Places SDK API key. Refer to
the Places SDK documentation for initial
setup instructions. It's important to restrict your key usage as
detailed here.
Replace "your-ios-api-key"
and "your-android-api-key"
with your actual API keys.
RNGooglePlacesCompat.initializePlaceClient(
Platform.OS === 'ios'
? "your-ios-api-key"
: "your-android-api-key",
true // If you want to enable [session tokens](https://developers.google.com/maps/documentation/places/web-service/session-tokens)
);
Once initialized, you can use the following methods to interact with the Google Places API:
RNGooglePlacesCompat.openAutocompleteModal()
RNGooglePlacesCompat.getAutocompletePredictions()
RNGooglePlacesCompat.getCurrentPlace()
RNGooglePlacesCompat.lookUpPlaceByID()
If you use getAutocompletePredictions
utilize session tokens to optimize API costs.
RNGooglePlacesCompat.setSessionBasedAutocomplete(true);
//or
RNGooglePlacesCompat.initializePlaceClient(apiKey, true);
// Token refresh is handled internally, but you can also call
RNGooglePlacesCompat.refreshSessionToken();
Refer examples in the example directory for more details.
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library