Gathering detailed insights and metrics for @nlabs/react-native-google-places
Gathering detailed insights and metrics for @nlabs/react-native-google-places
Gathering detailed insights and metrics for @nlabs/react-native-google-places
Gathering detailed insights and metrics for @nlabs/react-native-google-places
npm install @nlabs/react-native-google-places
Typescript
Module System
Node Version
NPM Version
29
Supply Chain
45.4
Quality
65.9
Maintenance
50
Vulnerability
93.6
License
Java (58.83%)
Objective-C (38.65%)
JavaScript (2.52%)
Total Downloads
1,073
Last Day
2
Last Week
4
Last Month
14
Last Year
152
71 Commits
2 Watching
3 Branches
2 Contributors
Latest Version
2.4.4
Package Id
@nlabs/react-native-google-places@2.4.4
Unpacked Size
1.23 MB
Size
1.08 MB
File Count
24
NPM Version
5.5.1
Node Version
9.3.0
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
0%
4
Compared to previous week
Last month
-36.4%
14
Compared to previous month
Last year
-9.5%
152
Compared to previous year
2
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'
and pod 'GoogleMaps'
to your Podfile. Otherwise just edit your Podfile to include:1source 'https://github.com/CocoaPods/Specs.git' 2 3target 'YOUR_APP_TARGET_NAME' do 4 5 pod 'GooglePlaces' 6 pod 'GoogleMaps' 7 pod 'GooglePlacePicker' 8 9end
use_frameworks!
in your Podfile@import GooglePlaces;
and @import GoogleMaps;
on top of the file.didFinishLaunchingWithOptions
method, instantiate the library as follows:1[GMSPlacesClient provideAPIKey:@"YOUR_IOS_API_KEY_HERE"]; 2[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:1<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 2<application 3 android:name=".MainApplication" 4 ...> 5 <meta-data 6 android:name="com.google.android.geo.API_KEY" 7 android:value="YOUR_ANDROID_API_KEY_HERE"/> 8 ... 9</application>
react-native link react-native-google-places
. Otherwise, do the following or just ensure they are in place;android/settings.gradle
file:1include ':react-native-google-places' 2project(':react-native-google-places').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places/android')
android/app/build.grade
file:1dependencies { 2 ... 3 compile project(':react-native-google-places') 4}
...MainApplication.java
file:1import com.arttitude360.reactnative.rngoogleplaces.RNGooglePlacesPackage; 2 3@Override 4protected List<ReactPackage> getPackages() { 5 return Arrays.<ReactPackage>asList( 6 new MainReactPackage(), 7 ... 8 new RNGooglePlacesPackage() //<-- Add line 9 ); 10}
react-native run-android
to get started.1import RNGooglePlaces from 'react-native-google-places';
1class GPlacesDemo extends Component { 2 openSearchModal() { 3 RNGooglePlaces.openAutocompleteModal() 4 .then((place) => { 5 console.log(place); 6 // place represents user's selection from the 7 // suggestions and it is a simplified Google Place object. 8 }) 9 .catch(error => console.log(error.message)); // error is a Javascript Error object 10 } 11 12 render() { 13 return ( 14 <View style={styles.container}> 15 <TouchableOpacity 16 style={styles.button} 17 onPress={() => this.openSearchModal()} 18 > 19 <Text>Pick a Place</Text> 20 </TouchableOpacity> 21 </View> 22 ); 23 } 24}
To filter autocomplete results as listed for Android and iOS in the official docs, you can pass an options
object as a parameter to the openAutocompleteModal()
method as follows:
1 RNGooglePlaces.openAutocompleteModal({ 2 type: 'establishment', 3 country: 'CA', 4 latitude: 53.544389, 5 longitude: -113.490927, 6 radius: 10 7 }) 8 .then((place) => { 9 console.log(place); 10 }) 11 .catch(error => console.log(error.message));
type
(String) - The type of results to return. Can be one of (geocode
, address
, establishment
, regions
, and cities
). (optional)country
(String) - Limit results to a specific country using a ISO 3166-1 Alpha-2 country code (case insensitive). If this is not set, no country filtering will take place. (optional)latitude
(Number) - Latitude of the point around which you wish to retrieve place information (required if longitude
is given)longitude
(Number) - Longitude of the point around which you wish to retrieve place information (required if latitude
is given)radius
(Number) - Radius (in kilo-meters) within which to retrieve place information. Only works if latitude
and longitude
are also given. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area. Defaults to 0.1
.useOverlay
(Boolean) [Android Only] - If true, the autocomplete modal will open as an overlay. Defaults to false
.1class GPlacesDemo extends Component { 2 openSearchModal() { 3 RNGooglePlaces.openPlacePickerModal() 4 .then((place) => { 5 console.log(place); 6 // place represents user's selection from the 7 // suggestions and it is a simplified Google Place object. 8 }) 9 .catch(error => console.log(error.message)); // error is a Javascript Error object 10 } 11 12 render() { 13 return ( 14 <View style={styles.container}> 15 <TouchableOpacity 16 style={styles.button} 17 onPress={() => this.openSearchModal()} 18 > 19 <Text>Open Place Picker</Text> 20 </TouchableOpacity> 21 </View> 22 ); 23 } 24}
To set the initial viewport that the place picker map should show when the picker is launched, you can pass a latLngBounds
object as a parameter
to the openPlacePickerModal()
method as follows. The latLngBounds
object takes the following optional keys:
latitude
(Number) - Latitude of the point which you want the map centered on (required if longitude
is given)longitude
(Number) - Longitude of the point which you want the map centered on (required if latitude
is given)radius
(Number) - Radius (in kilo-meters) from the center of the map view to the edge. Use this to set the default "zoom" of the map view when it is first opened. Only works if latitude
and longitude
are also given. Defaults to 0.1
.If no initial viewport is set (no argument is passed to the openPlacePickerModal()
method), the viewport will be centered on the device's location, with the zoom at city-block level.
1 RNGooglePlaces.openPlacePickerModal({ 2 latitude: 53.544389, 3 longitude: -113.490927, 4 radius: 0.01 // 10 meters 5 }) 6 .then((place) => { 7 console.log(place); 8 }) 9 .catch(error => console.log(error.message));
1{ 2 placeID: "ChIJZa6ezJa8j4AR1p1nTSaRtuQ", 3 website: "https://www.facebook.com/", 4 phoneNumber: "+1 650-543-4800", 5 address: "1 Hacker Way, Menlo Park, CA 94025, USA", 6 name: "Facebook HQ", 7 types: [ 'street_address', 'geocode' ], 8 latitude: 37.4843428, 9 longitude: -122.14839939999999 10}
Promise
from calling RNGooglePlaces.openAutocompleteModal()
are dependent on the selected place - as phoneNumber, website, north, south, east, west, priceLevel, rating
are not set on all Google Place
objects.This method returns to you the place where the device is currently located. That is, the place at the device's currently-reported location. For each place, the result includes an indication of the likelihood that the place is the right one. A higher value for likelihood
means a greater probability that the place is the best match.
1 RNGooglePlaces.getCurrentPlace() 2 .then((results) => console.log(results)) 3 .catch((error) => console.log(error.message));
1[{ name: 'Facebook HQ', 2 website: 'https://www.facebook.com/', 3 longitude: -122.14835169999999, 4 address: '1 Hacker Way, Menlo Park, CA 94025, USA', 5 latitude: 37.48485, 6 placeID: 'ChIJZa6ezJa8j4AR1p1nTSaRtuQ', 7 types: [ 'street_address', 'geocode' ], 8 phoneNumber: '+1 650-543-4800', 9 likelihood: 0.9663974, 10 ... 11},{ 12 ... 13}]
The sum of the likelihoods in a given result set is always less than or equal to 1.0. Note that the sum isn't necessarily 1.0.
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
.
1 RNGooglePlaces.getAutocompletePredictions('facebook') 2 .then((results) => this.setState({ predictions: results })) 3 .catch((error) => console.log(error.message));
To filter autocomplete results as listed for Android and iOS in the official docs, you can pass an options
object as a second parameter to the getAutocompletePredictions()
method as follows:
1 RNGooglePlaces.getAutocompletePredictions('Lagos', { 2 type: 'cities', 3 country: 'NG' 4 }) 5 .then((place) => { 6 console.log(place); 7 }) 8 .catch(error => console.log(error.message));
OR
1RNGooglePlaces.getAutocompletePredictions('pizza', { 2 type: 'establishments', 3 latitude: 53.544389, 4 longitude: -113.490927, 5 radius: 10 6 }) 7 .then((place) => { 8 console.log(place); 9 }) 10 .catch(error => console.log(error.message));
type
(String) - The type of results to return. Can be one of (geocode
, address
, establishment
, regions
, and cities
). (optional)country
(String) - Limit results to a specific country using a ISO 3166-1 Alpha-2 country code (case insensitive). If this is not set, no country filtering will take place. (optional)latitude
(Number) - Latitude of the point around which you wish to retrieve place information (required if longitude
is given)longitude
(Number) - Longitude of the point around which you wish to retrieve place information (required if latitude
is given)radius
(Number) - Radius (in kilo-meters) within which to retrieve place information. Only works if latitude
and longitude
are also given. Note that setting a radius biases results to the indicated area, but may not fully restrict results to the specified area. Defaults to 0.1
.1[ { primaryText: 'Facebook HQ', 2 placeID: 'ChIJZa6ezJa8j4AR1p1nTSaRtuQ', 3 secondaryText: 'Hacker Way, Menlo Park, CA, United States', 4 fullText: 'Facebook HQ, Hacker Way, Menlo Park, CA, United States' }, 5 types: [ 'street_address', 'geocode' ], 6 { primaryText: 'Facebook Way', 7 placeID: 'EitGYWNlYm9vayBXYXksIE1lbmxvIFBhcmssIENBLCBVbml0ZWQgU3RhdGVz', 8 secondaryText: 'Menlo Park, CA, United States', 9 fullText: 'Facebook Way, Menlo Park, CA, United States' }, 10 types: [ 'street_address', 'geocode' ], 11 12 ... 13]
1 const placeIDs = 'ChIJZa6ezJa8j4AR1p1nTSaRtuQ' || ['ChIJZa6ezJa8j4AR1p1nTSaRtuQ', 'other_place_id']; 2 RNGooglePlaces.lookUpPlaceByID(placeIDs) 3 .then((results) => console.log(results)) 4 .catch((error) => console.log(error.message));
1[ 2 { name: 'Facebook HQ', 3 website: 'https://www.facebook.com/', 4 longitude: -122.14835169999999, 5 address: '1 Hacker Way, Menlo Park, CA 94025, USA', 6 latitude: 37.48485, 7 placeID: 'ChIJZa6ezJa8j4AR1p1nTSaRtuQ', 8 types: [ 'street_address', 'geocode' ], 9 phoneNumber: '+1 650-543-4800', 10 } 11]
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 10.2.4), use the following instead (switch 10.2.0 for the desired version) in your android/app/build.grade
file:
1... 2dependencies { 3 ... 4 compile(project(':react-native-google-places')){ 5 exclude group: 'com.google.android.gms', module: 'play-services-base' 6 exclude group: 'com.google.android.gms', module: 'play-services-places' 7 exclude group: 'com.google.android.gms', module: 'play-services-location' 8 } 9 compile 'com.google.android.gms:play-services-base:10.2.0' 10 compile 'com.google.android.gms:play-services-places:10.2.0' 11 compile 'com.google.android.gms:play-services-location:10.2.0' 12}
The MIT License.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More