![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
react-native-google-places
Advanced tools
iOS/Android Google Places Widgets (Autocomplete, Place Picker) and API Services for React Native Apps
iOS/Android Google Places Widgets (Autocomplete, Place Picker) and API Services for React Native Apps
npm i react-native-google-places --save
react-native link react-native-google-places
OR
yarn add react-native-google-places
react-native link react-native-google-places
react-native link react-native-google-places
. Or you can run the command now if you have not already.Libraries ➜ Add Files to [your project's name]
.node_modules
➜ react-native-google-places
and add RNGooglePlaces.xcodeproj
.libRNGooglePlaces.a
to your project's Build Phases
➜ Link Binary With Libraries
.gem install cocoapods
to set it up the first time. (Hint: Go grab a cup of coffee!)cd ios && pod init
at the root directory of your project.pod 'GooglePlaces'
, (pod 'GooglePlacePicker'
only if you are using the PlacePickerModal) and pod 'GoogleMaps'
to your Podfile. Otherwise just edit your Podfile to include:source 'https://github.com/CocoaPods/Specs.git'
target 'YOUR_APP_TARGET_NAME' do
pod 'GooglePlaces'
pod 'GoogleMaps'
pod 'GooglePlacePicker'
end
@import GooglePlaces;
and @import GoogleMaps;
on top of the file.didFinishLaunchingWithOptions
method, instantiate the library as follows:[GMSPlacesClient provideAPIKey:@"YOUR_IOS_API_KEY_HERE"];
[GMSServices provideAPIKey:@"YOUR_IOS_API_KEY_HERE"];
pod install
from your ios
directory..xcworkspace
file to open the project. Or just use the react-native run-ios
command as usual to run your app in the simulator.<application>
tag as follows:<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:name=".MainApplication"
...>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_ANDROID_API_KEY_HERE"/>
...
</application>
react-native link react-native-google-places
. Otherwise, do the following or just ensure they are in place;android/settings.gradle
file:include ':react-native-google-places'
project(':react-native-google-places').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places/android')
android/app/build.grade
file:dependencies {
...
compile project(':react-native-google-places')
}
...MainApplication.java
file:import com.arttitude360.reactnative.rngoogleplaces.RNGooglePlacesPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
...
new RNGooglePlacesPackage() //<-- Add line
);
}
react-native run-android
to get started.import RNGooglePlaces from 'react-native-google-places';
class GPlacesDemo extends Component {
openSearchModal() {
RNGooglePlaces.openAutocompleteModal()
.then((place) => {
console.log(place);
// place represents user's selection from the
// suggestions and it is a simplified Google Place object.
})
.catch(error => console.log(error.message)); // error is a Javascript Error object
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity
style={styles.button}
onPress={() => this.openSearchModal()}
>
<Text>Pick a Place</Text>
</TouchableOpacity>
</View>
);
}
}
class GPlacesDemo extends Component {
openSearchModal() {
RNGooglePlaces.openPlacePickerModal()
.then((place) => {
console.log(place);
// place represents user's selection from the
// suggestions and it is a simplified Google Place object.
})
.catch(error => console.log(error.message)); // error is a Javascript Error object
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity
style={styles.button}
onPress={() => this.openSearchModal()}
>
<Text>Open Place Picker</Text>
</TouchableOpacity>
</View>
);
}
}
{
placeID: "ChIJZa6ezJa8j4AR1p1nTSaRtuQ",
website: "https://www.facebook.com/",
phoneNumber: "+1 650-543-4800",
address: "1 Hacker Way, Menlo Park, CA 94025, USA",
name: "Facebook HQ",
latitude: 37.4843428,
longitude: -122.14839939999999
}
Promise
from calling RNGooglePlaces.openAutocompleteModal()
are dependent on the selected place - as phoneNumber, website
are not set on all Google Place
objects.If you have specific branding needs or you would rather build out your own custom search input and suggestions list (think Uber
), you may profit from calling the API methods below which would get you autocomplete predictions programmatically using the underlying iOS and Android SDKs
.
RNGooglePlaces.getAutocompletePredictions('facebook')
.then((results) => this.state.predictions = results)
.catch((error) => console.log(error.message));
Or you may filter the predictions to specific type of places as contained in Google's Place API
documentations by passing in a second argument
to getAutocompletePredictions()
e.g. geocode
, address
, establishment
, regions
, and cities
.
RNGooglePlaces.getAutocompletePredictions('Paris', 'cities')
.then((results) => this.state.predictions = results)
.catch((error) => console.log(error.message));
[ { primaryText: 'Facebook HQ',
placeID: 'ChIJZa6ezJa8j4AR1p1nTSaRtuQ',
secondaryText: 'Hacker Way, Menlo Park, CA, United States',
fullText: 'Facebook HQ, Hacker Way, Menlo Park, CA, United States' },
{ primaryText: 'Facebook Way',
placeID: 'EitGYWNlYm9vayBXYXksIE1lbmxvIFBhcmssIENBLCBVbml0ZWQgU3RhdGVz',
secondaryText: 'Menlo Park, CA, United States',
fullText: 'Facebook Way, Menlo Park, CA, United States' },
...
]
RNGooglePlaces.lookUpPlaceByID('ChIJZa6ezJa8j4AR1p1nTSaRtuQ')
.then((results) => console.log(results))
.catch((error) => console.log(error.message));
{ name: 'Facebook HQ',
website: 'https://www.facebook.com/',
longitude: -122.14835169999999,
address: '1 Hacker Way, Menlo Park, CA 94025, USA',
latitude: 37.48485,
placeID: 'ChIJZa6ezJa8j4AR1p1nTSaRtuQ',
phoneNumber: '+1 650-543-4800'
}
The typical use flow would be to call getAutocompletePredictions()
when the value of your search input changes to populate your suggestion listview and call lookUpPlaceByID()
to retrieve the place details when a place on your listview is selected.
getAutocompletePredictions()
method is subject to tiered query limits. See the documentation on Android & iOS Usage Limits.You have to link dependencies and re-run the build:
react-native link
Manual Linking With Your Project
steps above.react-native run-ios
Extras / Google Play services
Extras / Google Repository
Android (API 23+) / Google APIs Intel x86 Atom System Image Rev. 13
Check manual installation steps
Ensure your API key has permissions for Google Place
and Google Android Maps
If you have a different version of play serivces than the one included in this library (which is currently at 9.8.0), use the following instead (switch 10.0.1 for the desired version) in your android/app/build.grade
file:
...
dependencies {
...
compile(project(':react-native-google-places')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-places'
exclude group: 'com.google.android.gms', module: 'play-services-location'
}
compile 'com.google.android.gms:play-services-base:10.0.1'
compile 'com.google.android.gms:play-services-places:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
}
The MIT License.
FAQs
iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps
The npm package react-native-google-places receives a total of 842 weekly downloads. As such, react-native-google-places popularity was classified as not popular.
We found that react-native-google-places demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.