@korekoi/react-native-google-places
v0.0.7
Published
A React Native library for Google Places API, providing geocoding, autocomplete, and more.
Readme
@korekoi/react-native-google-places
Nitro wrapper around the Google Places SDK with a single API for address autocomplete.
Reasons to use this module:
- You can now use the Google Places SDK in your React Native app providing a restricted API key on your bundle identifiers so that you don't have to expose an open API key to the public.
- The module provides a simple API for address autocomplete, returning only the place ID and a display string for UI
Install
npm install @korekoi/react-native-google-places react-native-nitro-modulescd ios && pod installAPI key setup
You can set the API key either manually or via the Expo config plugin.
Expo config plugin (iOS + Android)
{
"expo": {
"plugins": [
[
"@korekoi/react-native-google-places",
{ "androidApiKey": "YOUR_ANDROID_API_KEY", "iosApiKey": "YOUR_IOS_API_KEY" }
]
]
}
}Manual setup
iOS
Add GMSPlacesAPIKey to Info.plist:
<key>GMSPlacesAPIKey</key>
<string>YOUR_IOS_API_KEY</string>Android
Add the meta-data entry in AndroidManifest.xml:
<application>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_ANDROID_API_KEY" />
</application>Usage
import places from '@korekoi/react-native-google-places'
const results = await places.autocomplete('1600 Amphitheatre Pkwy, Mountain View')
// results: Array<{ placeId: string; label: string }>API
autocomplete(query: string)
Returns a list of results with:
placeId: the place idlabel: full display string for UI
Notes
- iOS initializes the SDK using
GMSPlacesAPIKeyfromInfo.plist. - Android reads the key from
com.google.android.geo.API_KEYin the manifest. - Requires
react-native-nitro-modulesand generated Nitro code innitrogen/.
Development
npm run specsLicense
MIT
