From 9970b9717b5bab6ef86b089884a7ae8ce87ebe31 Mon Sep 17 00:00:00 2001 From: Amin ulhaq <46367458+Amenulhaq@users.noreply.github.com> Date: Mon, 15 Mar 2021 19:13:34 +0500 Subject: [PATCH 01/26] Update RNGooglePlacesViewController.m Fix DarkMode issue on iOS 13 --- ios/RNGooglePlacesViewController.m | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ios/RNGooglePlacesViewController.m b/ios/RNGooglePlacesViewController.m index ea60607..29541a6 100644 --- a/ios/RNGooglePlacesViewController.m +++ b/ios/RNGooglePlacesViewController.m @@ -35,6 +35,19 @@ - (void)openAutocompleteModal: (GMSAutocompleteFilter *)autocompleteFilter _reject = reject; GMSAutocompleteViewController *viewController = [[GMSAutocompleteViewController alloc] init]; + if (@available(iOS 13.0, *)) { + if(UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark ){ + viewController.primaryTextColor = UIColor.whiteColor; + viewController.secondaryTextColor = UIColor.lightGrayColor; + viewController.tableCellSeparatorColor = UIColor.lightGrayColor; + viewController.tableCellBackgroundColor = UIColor.darkGrayColor; + } else { + viewController.primaryTextColor = UIColor.blackColor; + viewController.secondaryTextColor = UIColor.lightGrayColor; + viewController.tableCellSeparatorColor = UIColor.lightGrayColor; + viewController.tableCellBackgroundColor = UIColor.whiteColor; + } + } viewController.autocompleteFilter = autocompleteFilter; viewController.autocompleteBounds = autocompleteBounds; viewController.autocompleteBoundsMode = autocompleteBoundsMode; @@ -96,4 +109,4 @@ - (UIViewController *)getTopController return topController; } -@end \ No newline at end of file +@end From f0eb3cea107085f939f07fa740683aa81c7e8cee Mon Sep 17 00:00:00 2001 From: Amin Satti Date: Mon, 15 Mar 2021 19:26:46 +0500 Subject: [PATCH 02/26] update package.json for npmjs --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e847651..a10ac7c 100644 --- a/package.json +++ b/package.json @@ -2,19 +2,19 @@ "name": "react-native-google-places", "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", - "author": "Tolu Olowu (Arttitude 360) ", - "version": "3.1.2", + "author": "Amenulhaq ", + "version": "1.0.0", "scripts": {}, "repository": { "type": "git", - "url": "https://github.com/tolu360/react-native-google-places" + "url": "git+https://github.com/Amenulhaq/react-native-google-places.git" }, "license": "MIT", "bugs": { - "url": "https://github.com/tolu360/react-native-google-places/issues" + "url": "https://github.com/Amenulhaq/react-native-google-places/issues" }, "types": "index.d.ts", - "homepage": "https://github.com/tolu360/react-native-google-places#readme", + "homepage": "https://github.com/Amenulhaq/react-native-google-places#readme", "keywords": [ "react", "react-native", @@ -32,4 +32,4 @@ "react-native": ">=0.40.0" }, "devDependencies": {} -} \ No newline at end of file +} From 8f1d5893d6f2a6d64cb5a4659effcf57e4799fc3 Mon Sep 17 00:00:00 2001 From: Amin Satti Date: Mon, 15 Mar 2021 19:42:05 +0500 Subject: [PATCH 03/26] update version and package name --- .gitignore | 2 +- README.md | 30 +++++++++++++--------------- READMEV2.md | 32 ++++++++++++++---------------- index.d.ts | 2 +- package.json | 8 ++++---- react-native-google-places.podspec | 4 ++-- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index 50c7247..e4ca1d7 100644 --- a/.gitignore +++ b/.gitignore @@ -55,7 +55,7 @@ project.xcworkspace # Android/IJ # -react-native-google-places.iml +react-native-google-places-api.iml .idea .gradle .vscode diff --git a/README.md b/README.md index eb0b880..bdb20ad 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# react-native-google-places +# react-native-google-places-api iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for React Native Apps ### **Notice: The Google Play Services version of the Places SDK for Android (in Google Play Services 16.0.0) is deprecated as of January 29, 2019, and will be turned off on July 29, 2019. A new version of the Places SDK for Android is now available. I suggest you read the documentations again and update your app to use v3.0.1 (or above) of this package** @@ -13,21 +13,19 @@ iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for Reac ## Versioning: -- for RN >= 0.40.0, use v3+ (e.g. react-native-google-places@3.1.0) +- for RN >= 0.40.0, use v3+ (e.g. react-native-google-places-api@1.0.0) - If you are still using the v2 of this library, you really should not, then **[Version 2 Documentations](/READMEV2.md)** -## Sample App -- A new [Sample App](https://github.com/tolu360/RNGPDemos) is available to help with sample usage and debugging issues. ## Install ``` -npm i react-native-google-places --save +npm i react-native-google-places-api --save ``` OR ``` -yarn add react-native-google-places +yarn add react-native-google-places-api ``` #### Google Places API Set-Up @@ -43,7 +41,7 @@ yarn add react-native-google-places ##### 1) Auto Linking & Cocoapods Integration - If you do not have CocoaPods already installed on your machine, run `gem install cocoapods` to set it up the first time. (Hint: Go grab a cup of coffee!) - If you are not using Cocoapods in your project already, run `cd ios && pod init` at the root directory of your project. This would create a `Podfile` in your `ios` directory. -- Run `react-native link react-native-google-places` at the root directory of your project and ensure you edit your Podfile to look like the sample below (remove all the targets you are not building for, such as Tests and tvOS): +- Run `react-native link react-native-google-places-api` at the root directory of your project and ensure you edit your Podfile to look like the sample below (remove all the targets you are not building for, such as Tests and tvOS): ```ruby # platform :ios, '9.0' @@ -71,13 +69,13 @@ target '_YOUR_PROJECT_TARGET_' do pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' # This should already be auto-added for you, if not add the line below - pod 'react-native-google-places', :path => '../node_modules/react-native-google-places' + pod 'react-native-google-places-api', :path => '../node_modules/react-native-google-places-api' end post_install do |installer| installer.pods_project.targets.each do |target| - if target.name == 'react-native-google-places' + if target.name == 'react-native-google-places-api' target.build_configurations.each do |config| config.build_settings['CLANG_ENABLE_MODULES'] = 'No' end @@ -120,7 +118,7 @@ on top of the file. #### Post-Install Steps (Android) ##### Auto Linking With Your Project -- This was done automatically for you when you ran `react-native link react-native-google-places`. Or you can run the command now if you have not already. +- This was done automatically for you when you ran `react-native link react-native-google-places-api`. Or you can run the command now if you have not already. - In your `AndroidManifest.xml` file, request the following permissions: ```xml @@ -136,19 +134,19 @@ RNGP_ANDROID_API_KEY=Insert_API_KEY_here ``` ##### Manual Linking With Your Project (Android) -- The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places`. Otherwise, do the following or just ensure they are in place; +- The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places-api`. Otherwise, do the following or just ensure they are in place; - Add the following in your `android/settings.gradle` file: ```groovy -include ':react-native-google-places' -project(':react-native-google-places').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places/android') +include ':react-native-google-places-api' +project(':react-native-google-places-api').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places-api/android') ``` - Add the following in your `android/app/build.grade` file: ```groovy dependencies { ... - compile project(':react-native-google-places') + compile project(':react-native-google-places-api') } ``` @@ -213,7 +211,7 @@ android { #### Import library ```javascript -import RNGooglePlaces from 'react-native-google-places'; +import RNGooglePlaces from 'react-native-google-places-api'; ``` #### Open Autocomplete Modal (e.g as Callback to an onPress event) @@ -531,7 +529,7 @@ end - Consult the [usage](https://github.com/orta/cocoapods-keys#usage) and [alternative usage](https://github.com/orta/cocoapods-keys#alternative-usage) sections of the `cocoapods-keys` repo to learn how to add your API key to keychain on the Mac. - Set up your key with `cocoapods-keys` with either of the instructions from the line above. - Run `pod install` again from your `/ios` directory. -- Replace the string versions of your key in your `AppDelegate.m` file. You can review a sample usage in the [Sample App](https://github.com/tolu360/RNGPDemos) +- Replace the string versions of your key in your `AppDelegate.m` file. - You may skip these steps and continue to have your API key directly in `AppDelegate.m`, things would work just as fine. diff --git a/READMEV2.md b/READMEV2.md index 895d82d..0066aad 100644 --- a/READMEV2.md +++ b/READMEV2.md @@ -1,4 +1,4 @@ -# react-native-google-places +# react-native-google-places-api iOS/Android Google Places Widgets (Autocomplete, Place Picker) and API Services for React Native Apps ### **Notice: The Google Play Services version of the Places SDK for Android (in Google Play Services 16.0.0) is deprecated as of January 29, 2019, and will be turned off on July 29, 2019. A new version of the Places SDK for Android is now available.** @@ -15,24 +15,22 @@ iOS/Android Google Places Widgets (Autocomplete, Place Picker) and API Services ## Versioning: -- for RN >= 0.40.0, use v2+ (e.g. react-native-google-places@2.5.2) +- for RN >= 0.40.0, use v2+ (e.g. react-native-google-places-api@1.0.0) ### I recommend you migrate your applications to the version 3.0.1 (or above) of this package - Heads up! There are tons of breaking changes in the new release. **[Visit the updated README to get started](/README.md)** -## Sample App -- A new [sample app](https://github.com/tolu360/TestRNGP) is available to help with sample usage and debugging issues. ## Install ``` -npm i react-native-google-places --save -react-native link react-native-google-places +npm i react-native-google-places-api --save +react-native link react-native-google-places-api ``` OR ``` -yarn add react-native-google-places -react-native link react-native-google-places +yarn add react-native-google-places-api +react-native link react-native-google-places-api ``` @@ -48,11 +46,11 @@ react-native link react-native-google-places ##### iOS (requires CocoaPods) ##### Auto Linking With Your Project (iOS & Android) -- This was done automatically for you when you ran `react-native link react-native-google-places`. Or you can run the command now if you have not already. +- This was done automatically for you when you ran `react-native link react-native-google-places-api`. Or you can run the command now if you have not already. ##### Manual Linking With Your Project (iOS) - In XCode, in the project navigator, right click `Libraries ➜ Add Files to [your project's name]`. -- Go to `node_modules` ➜ `react-native-google-places` and add `RNGooglePlaces.xcodeproj`. +- Go to `node_modules` ➜ `react-native-google-places-api` and add `RNGooglePlaces.xcodeproj`. - In XCode, in the project navigator, select your project. Add `libRNGooglePlaces.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`. ##### Install CocoaPods Dependencies @@ -96,19 +94,19 @@ end ``` ##### Manual Linking With Your Project (Android) -- The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places`. Otherwise, do the following or just ensure they are in place; +- The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places-api`. Otherwise, do the following or just ensure they are in place; - Add the following in your `android/settings.gradle` file: ```groovy -include ':react-native-google-places' -project(':react-native-google-places').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places/android') +include ':react-native-google-places-api' +project(':react-native-google-places-api').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places-api/android') ``` - Add the following in your `android/app/build.grade` file: ```groovy dependencies { ... - compile project(':react-native-google-places') + compile project(':react-native-google-places-api') } ``` @@ -177,7 +175,7 @@ If you do **not** have *project-wide properties* defined or want to use a differ ... dependencies { ... - compile(project(':react-native-google-places')){ + compile(project(':react-native-google-places-api')){ 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' @@ -196,7 +194,7 @@ If you do **not** have *project-wide properties* defined or want to use a differ #### Import library ```javascript -import RNGooglePlaces from 'react-native-google-places'; +import RNGooglePlaces from 'react-native-google-places-api'; ``` #### Open Autocomplete Modal (e.g as Callback to an onPress event) @@ -486,7 +484,7 @@ You have to link dependencies and re-run the build: ... dependencies { ... - compile(project(':react-native-google-places')){ + compile(project(':react-native-google-places-api')){ 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' diff --git a/index.d.ts b/index.d.ts index 30d7127..ac58127 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -declare module "react-native-google-places" { +declare module "react-native-google-places-api" { /** * 2D Coordinate bounds for view boxes etc, as defined by the bottom left and * top right corners. diff --git a/package.json b/package.json index a10ac7c..94b1b5c 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "react-native-google-places", + "name": "react-native-google-places-api", "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", "author": "Amenulhaq ", @@ -7,14 +7,14 @@ "scripts": {}, "repository": { "type": "git", - "url": "git+https://github.com/Amenulhaq/react-native-google-places.git" + "url": "git+https://github.com/Amenulhaq/react-native-google-places-api.git" }, "license": "MIT", "bugs": { - "url": "https://github.com/Amenulhaq/react-native-google-places/issues" + "url": "https://github.com/Amenulhaq/react-native-google-places-api/issues" }, "types": "index.d.ts", - "homepage": "https://github.com/Amenulhaq/react-native-google-places#readme", + "homepage": "https://github.com/Amenulhaq/react-native-google-places-api#readme", "keywords": [ "react", "react-native", diff --git a/react-native-google-places.podspec b/react-native-google-places.podspec index 7445c14..292bb1c 100644 --- a/react-native-google-places.podspec +++ b/react-native-google-places.podspec @@ -8,8 +8,8 @@ Pod::Spec.new do |s| s.description = package['description'] s.license = package['license'] s.author = package['author'] - s.homepage = 'https://github.com/tolu360/react-native-google-places' - s.source = { :git => 'https://github.com/tolu360/react-native-google-places.git', :tag => s.version } + s.homepage = 'https://github.com/Amenulhaq/react-native-google-places-api' + s.source = { :git => 'https://github.com/Amenulhaq/react-native-google-places-api.git', :tag => s.version } s.platform = :ios, '9.0' From 964f60d71b866189c4a5dc3f3fba2697c01390d9 Mon Sep 17 00:00:00 2001 From: Amin Satti Date: Tue, 16 Mar 2021 11:04:28 +0500 Subject: [PATCH 04/26] 1.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94b1b5c..9a8c3cf 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", "author": "Amenulhaq ", - "version": "1.0.0", + "version": "1.0.1", "scripts": {}, "repository": { "type": "git", From af523a2c61f01696e104b1ceb566f53268bd6635 Mon Sep 17 00:00:00 2001 From: Amin Satti Date: Tue, 16 Mar 2021 11:26:02 +0500 Subject: [PATCH 05/26] update version number add more keywords in package.json --- README.md | 4 +++- READMEV2.md | 4 +++- package.json | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bdb20ad..24eddab 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,8 @@ iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for Reac ### **Notice: The Google Play Services version of the Places SDK for Android (in Google Play Services 16.0.0) is deprecated as of January 29, 2019, and will be turned off on July 29, 2019. A new version of the Places SDK for Android is now available. I suggest you read the documentations again and update your app to use v3.0.1 (or above) of this package** +### Also support dark mode for iOS 13 and above ** + ## Shots @@ -13,7 +15,7 @@ iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for Reac ## Versioning: -- for RN >= 0.40.0, use v3+ (e.g. react-native-google-places-api@1.0.0) +- for RN >= 0.40.0, use v3+ (e.g. react-native-google-places-api@1.0.2) - If you are still using the v2 of this library, you really should not, then **[Version 2 Documentations](/READMEV2.md)** diff --git a/READMEV2.md b/READMEV2.md index 0066aad..409c588 100644 --- a/READMEV2.md +++ b/READMEV2.md @@ -5,6 +5,8 @@ iOS/Android Google Places Widgets (Autocomplete, Place Picker) and API Services ### I recommend you migrate your applications to the version 3.0.1 (or above) of this package - Heads up! There are tons of breaking changes in the new release. **[Visit the updated README to get started](/README.md)** +### Also support dark mode for iOS 13 and above ** + ## Shots @@ -15,7 +17,7 @@ iOS/Android Google Places Widgets (Autocomplete, Place Picker) and API Services ## Versioning: -- for RN >= 0.40.0, use v2+ (e.g. react-native-google-places-api@1.0.0) +- for RN >= 0.40.0, use v2+ (e.g. react-native-google-places-api@1.0.2) ### I recommend you migrate your applications to the version 3.0.1 (or above) of this package - Heads up! There are tons of breaking changes in the new release. **[Visit the updated README to get started](/README.md)** diff --git a/package.json b/package.json index 9a8c3cf..a57c79b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", "author": "Amenulhaq ", - "version": "1.0.1", + "version": "1.0.2", "scripts": {}, "repository": { "type": "git", @@ -23,6 +23,9 @@ "places", "google-places", "Google Places API", + "Google places darkmode", + "Google darkmode", + "darkmode autocomplete", "autocomplete", "ios", "android" From e4aad0ea38654255b28d656e35fb7b42bf7996d7 Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 19:08:22 +0800 Subject: [PATCH 06/26] Updated dependency to 5.1.0 --- react-native-google-places.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/react-native-google-places.podspec b/react-native-google-places.podspec index 292bb1c..cc0133d 100644 --- a/react-native-google-places.podspec +++ b/react-native-google-places.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.homepage = 'https://github.com/Amenulhaq/react-native-google-places-api' s.source = { :git => 'https://github.com/Amenulhaq/react-native-google-places-api.git', :tag => s.version } - s.platform = :ios, '9.0' + s.platform = :ios, '11.0' s.preserve_paths = 'README.md', 'package.json', 'index.js' s.source_files = 'ios/*.{h,m}' @@ -19,6 +19,6 @@ Pod::Spec.new do |s| s.compiler_flags = '-DHAVE_GOOGLE_MAPS=1', '-fno-modules' s.dependency 'React' - s.dependency 'GooglePlaces', '~> 3.1.0' - s.dependency 'GoogleMaps', '~> 3.1.0' + s.dependency 'GooglePlaces', '~> 5.1.0' + s.dependency 'GoogleMaps', '~> 5.1.0' end \ No newline at end of file From b572c5464ca35500001dcae6532c209670813312 Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 19:19:37 +0800 Subject: [PATCH 07/26] Removed autocomplete modal --- ios/RNGooglePlaces.m | 66 +++++++++--------------------- ios/RNGooglePlacesViewController.h | 8 ---- ios/RNGooglePlacesViewController.m | 47 ++++----------------- 3 files changed, 26 insertions(+), 95 deletions(-) diff --git a/ios/RNGooglePlaces.m b/ios/RNGooglePlaces.m index 4b8f3f9..0dff510 100644 --- a/ios/RNGooglePlaces.m +++ b/ios/RNGooglePlaces.m @@ -40,10 +40,10 @@ - (instancetype)init _instance = self; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; - + self.boundsMode = kGMSAutocompleteBoundsModeBias; } - + return self; } @@ -52,34 +52,6 @@ - (void)dealloc self.locationManager = nil; } -RCT_EXPORT_METHOD(openAutocompleteModal: (NSDictionary *)options - withFields: (NSArray *)fields - resolver: (RCTPromiseResolveBlock)resolve - rejecter: (RCTPromiseRejectBlock)reject) -{ - - @try { - RNGooglePlacesViewController* acController = [[RNGooglePlacesViewController alloc] init]; - - GMSPlaceField selectedFields = [self getSelectedFields:fields isCurrentOrFetchPlace:false]; - - GMSAutocompleteFilter *autocompleteFilter = [[GMSAutocompleteFilter alloc] init]; - autocompleteFilter.type = [self getFilterType:[RCTConvert NSString:options[@"type"]]]; - autocompleteFilter.country = [options[@"country"] length] == 0? nil : options[@"country"]; - - NSDictionary *locationBias = [RCTConvert NSDictionary:options[@"locationBias"]]; - NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]]; - - - GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; - - [acController openAutocompleteModal: autocompleteFilter placeFields: selectedFields bounds: autocompleteBounds boundsMode: self.boundsMode resolver: resolve rejecter: reject]; - } - @catch (NSException * e) { - reject(@"E_OPEN_FAILED", @"Could not open modal", [self errorFromException:e]); - } -} - RCT_EXPORT_METHOD(getAutocompletePredictions: (NSString *)query filterOptions: (NSDictionary *)options resolver: (RCTPromiseResolveBlock)resolve @@ -89,14 +61,14 @@ - (void)dealloc GMSAutocompleteFilter *autocompleteFilter = [[GMSAutocompleteFilter alloc] init]; autocompleteFilter.type = [self getFilterType:[RCTConvert NSString:options[@"type"]]]; autocompleteFilter.country = [options[@"country"] length] == 0? nil : options[@"country"]; - + NSDictionary *locationBias = [RCTConvert NSDictionary:options[@"locationBias"]]; NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]]; - + GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; - + GMSAutocompleteSessionToken *token = [[GMSAutocompleteSessionToken alloc] init]; - + [[GMSPlacesClient sharedClient] findAutocompletePredictionsFromQuery:query bounds:autocompleteBounds boundsMode:self.boundsMode @@ -111,20 +83,20 @@ - (void)dealloc if (results != nil) { for (GMSAutocompletePrediction* result in results) { NSMutableDictionary *placeData = [[NSMutableDictionary alloc] init]; - + placeData[@"fullText"] = result.attributedFullText.string; placeData[@"primaryText"] = result.attributedPrimaryText.string; placeData[@"secondaryText"] = result.attributedSecondaryText.string; placeData[@"placeID"] = result.placeID; placeData[@"types"] = result.types; - + [autoCompleteSuggestionsList addObject:placeData]; } - + resolve(autoCompleteSuggestionsList); } - + }]; } @@ -141,7 +113,7 @@ - (void)dealloc reject(@"E_PLACE_DETAILS_ERROR", [error localizedDescription], nil); return; } - + if (place != nil) { resolve([NSMutableDictionary dictionaryWithGMSPlace:place]); } else { @@ -155,7 +127,7 @@ - (void)dealloc rejecter: (RCTPromiseRejectBlock)reject) { [self.locationManager requestAlwaysAuthorization]; - + GMSPlaceField selectedFields = [self getSelectedFields:fields isCurrentOrFetchPlace:true]; @@ -189,7 +161,7 @@ - (NSError *) errorFromException: (NSException *) exception @"callStackSymbols": exception.callStackSymbols, @"userInfo": exception.userInfo }; - + return [[NSError alloc] initWithDomain: @"RNGooglePlaces" code: 0 userInfo: exceptionInfo]; @@ -231,7 +203,7 @@ - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boo @"addressComponents" : @(GMSPlaceFieldAddressComponents), @"photos" : @(GMSPlaceFieldPhotos), }; - + if ([fields count] == 0 && !currentOrFetch) { return GMSPlaceFieldAll; } @@ -269,7 +241,7 @@ - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boo } return placeFields; } - + return GMSPlaceFieldAll; } @@ -292,19 +264,19 @@ - (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOpti coordinate:swBoundsCorner]; return bounds; - } + } if (restrictLatitudeSW != 0 && restrictLongitudeSW != 0 && restrictLatitudeNE != 0 && restrictLongitudeNE != 0) { CLLocationCoordinate2D neBoundsCorner = CLLocationCoordinate2DMake(restrictLatitudeNE, restrictLongitudeNE); CLLocationCoordinate2D swBoundsCorner = CLLocationCoordinate2DMake(restrictLatitudeSW, restrictLongitudeSW); GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:neBoundsCorner coordinate:swBoundsCorner]; - + self.boundsMode = kGMSAutocompleteBoundsModeRestrict; - + return bounds; } - + return nil; } diff --git a/ios/RNGooglePlacesViewController.h b/ios/RNGooglePlacesViewController.h index ca969fd..ff19032 100644 --- a/ios/RNGooglePlacesViewController.h +++ b/ios/RNGooglePlacesViewController.h @@ -9,12 +9,4 @@ - (instancetype) init; -- (void)openAutocompleteModal: (GMSAutocompleteFilter *)autocompleteFilter - placeFields: (GMSPlaceField)selectedFields - bounds: (GMSCoordinateBounds *)autocompleteBounds - boundsMode: (GMSAutocompleteBoundsMode)autocompleteBoundsMode - resolver: (RCTPromiseResolveBlock)resolve - rejecter: (RCTPromiseRejectBlock)reject; - - @end diff --git a/ios/RNGooglePlacesViewController.m b/ios/RNGooglePlacesViewController.m index 29541a6..28dd6bd 100644 --- a/ios/RNGooglePlacesViewController.m +++ b/ios/RNGooglePlacesViewController.m @@ -16,7 +16,7 @@ @implementation RNGooglePlacesViewController RCTPromiseRejectBlock _reject; } -- (instancetype)init +- (instancetype)init { self = [super init]; _instance = self; @@ -24,53 +24,20 @@ - (instancetype)init return self; } -- (void)openAutocompleteModal: (GMSAutocompleteFilter *)autocompleteFilter - placeFields: (GMSPlaceField)selectedFields - bounds: (GMSCoordinateBounds *)autocompleteBounds - boundsMode: (GMSAutocompleteBoundsMode)autocompleteBoundsMode - resolver: (RCTPromiseResolveBlock)resolve - rejecter: (RCTPromiseRejectBlock)reject; -{ - _resolve = resolve; - _reject = reject; - - GMSAutocompleteViewController *viewController = [[GMSAutocompleteViewController alloc] init]; - if (@available(iOS 13.0, *)) { - if(UIScreen.mainScreen.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark ){ - viewController.primaryTextColor = UIColor.whiteColor; - viewController.secondaryTextColor = UIColor.lightGrayColor; - viewController.tableCellSeparatorColor = UIColor.lightGrayColor; - viewController.tableCellBackgroundColor = UIColor.darkGrayColor; - } else { - viewController.primaryTextColor = UIColor.blackColor; - viewController.secondaryTextColor = UIColor.lightGrayColor; - viewController.tableCellSeparatorColor = UIColor.lightGrayColor; - viewController.tableCellBackgroundColor = UIColor.whiteColor; - } - } - viewController.autocompleteFilter = autocompleteFilter; - viewController.autocompleteBounds = autocompleteBounds; - viewController.autocompleteBoundsMode = autocompleteBoundsMode; - viewController.placeFields = selectedFields; - viewController.delegate = self; - UIViewController *topController = [self getTopController]; - [topController presentViewController:viewController animated:YES completion:nil]; -} - // Handle the user's selection. - (void)viewController:(GMSAutocompleteViewController *)viewController - didAutocompleteWithPlace:(GMSPlace *)place + didAutocompleteWithPlace:(GMSPlace *)place { UIViewController *topController = [self getTopController]; [topController dismissViewControllerAnimated:YES completion:nil]; - + if (_resolve) { _resolve([NSMutableDictionary dictionaryWithGMSPlace:place]); } } - (void)viewController:(GMSAutocompleteViewController *)viewController - didFailAutocompleteWithError:(NSError *)error + didFailAutocompleteWithError:(NSError *)error { UIViewController *topController = [self getTopController]; [topController dismissViewControllerAnimated:YES completion:nil]; @@ -82,7 +49,7 @@ - (void)viewController:(GMSAutocompleteViewController *)viewController } // User canceled the operation. -- (void)wasCancelled:(GMSAutocompleteViewController *)viewController +- (void)wasCancelled:(GMSAutocompleteViewController *)viewController { UIViewController *topController = [self getTopController]; [topController dismissViewControllerAnimated:YES completion:nil]; @@ -91,12 +58,12 @@ - (void)wasCancelled:(GMSAutocompleteViewController *)viewController } // Turn the network activity indicator on and off again. -- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController +- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; } -- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController +- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; } From 26eb763582076c1ed1cf7f04d3908b9e71f48c9b Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 19:24:06 +0800 Subject: [PATCH 08/26] `place.viewport` -> `place.viewportInfo` --- ios/NSMutableDictionary+GMSPlace.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ios/NSMutableDictionary+GMSPlace.m b/ios/NSMutableDictionary+GMSPlace.m index bd37cf1..1c02255 100644 --- a/ios/NSMutableDictionary+GMSPlace.m +++ b/ios/NSMutableDictionary+GMSPlace.m @@ -48,12 +48,12 @@ + (instancetype)dictionaryWithGMSPlace:(GMSPlace*)place placeData[@"rating"] = [NSNumber numberWithDouble:place.rating]; } - if (place.viewport) { + if (place.viewportInfo) { NSMutableDictionary *viewportMap = [[NSMutableDictionary alloc] init]; - viewportMap[@"latitudeNE"] = [NSNumber numberWithDouble:place.viewport.northEast.latitude]; - viewportMap[@"longitudeNE"] = [NSNumber numberWithDouble:place.viewport.northEast.longitude]; - viewportMap[@"latitudeSW"] = [NSNumber numberWithDouble:place.viewport.southWest.latitude]; - viewportMap[@"longitudeSW"] = [NSNumber numberWithDouble:place.viewport.southWest.longitude]; + viewportMap[@"latitudeNE"] = [NSNumber numberWithDouble:place.viewportInfo.northEast.latitude]; + viewportMap[@"longitudeNE"] = [NSNumber numberWithDouble:place.viewportInfo.northEast.longitude]; + viewportMap[@"latitudeSW"] = [NSNumber numberWithDouble:place.viewportInfo.southWest.latitude]; + viewportMap[@"longitudeSW"] = [NSNumber numberWithDouble:place.viewportInfo.southWest.longitude]; placeData[@"viewport"] = viewportMap; } From c138caf48770606bea7ed532a53ab00443080e7b Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 19:39:23 +0800 Subject: [PATCH 09/26] Commented `GMSCoordinateBounds` lines until it is properly replaced with the updated autocompleteFilter --- ios/RNGooglePlaces.h | 4 ++-- ios/RNGooglePlaces.m | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ios/RNGooglePlaces.h b/ios/RNGooglePlaces.h index c181afb..006d2b0 100644 --- a/ios/RNGooglePlaces.h +++ b/ios/RNGooglePlaces.h @@ -10,7 +10,7 @@ - (GMSPlacesAutocompleteTypeFilter) getFilterType:(NSString *)type; - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boolean)currentOrFetch; -- (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions; +/// TODO: 5.1.0 Update +// - (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions; @end - \ No newline at end of file diff --git a/ios/RNGooglePlaces.m b/ios/RNGooglePlaces.m index 0dff510..0189fd1 100644 --- a/ios/RNGooglePlaces.m +++ b/ios/RNGooglePlaces.m @@ -13,7 +13,8 @@ @interface RNGooglePlaces() @property (strong, nonatomic) CLLocationManager *locationManager; -@property GMSAutocompleteBoundsMode boundsMode; +/// TODO: 5.1.0 Update +// @property GMSAutocompleteBoundsMode boundsMode; @end @@ -41,7 +42,8 @@ - (instancetype)init self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; - self.boundsMode = kGMSAutocompleteBoundsModeBias; + /// TODO: 5.1.0 Update + /// self.boundsMode = kGMSAutocompleteBoundsModeBias; } return self; @@ -65,13 +67,12 @@ - (void)dealloc NSDictionary *locationBias = [RCTConvert NSDictionary:options[@"locationBias"]]; NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]]; - GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; + /// TODO: 5.1.0 Update + /// GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; GMSAutocompleteSessionToken *token = [[GMSAutocompleteSessionToken alloc] init]; [[GMSPlacesClient sharedClient] findAutocompletePredictionsFromQuery:query - bounds:autocompleteBounds - boundsMode:self.boundsMode filter:autocompleteFilter sessionToken:token callback:^(NSArray * _Nullable results, NSError *error) { @@ -245,6 +246,8 @@ - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boo return GMSPlaceFieldAll; } +/// TODO: 5.1.0 Update +/* - (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions { double biasLatitudeSW = [[RCTConvert NSNumber:biasOptions[@"latitudeSW"]] doubleValue]; @@ -279,7 +282,7 @@ - (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOpti return nil; } - +*/ @end From 50bf64c95cd3c7b8b62a554cd78854ba37a651ef Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 19:49:06 +0800 Subject: [PATCH 10/26] Updated README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 24eddab..70ba211 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# Hello + +- This package was updated to use 5.1.0 (Places for iOS SDK) +- This won't be regularly updated + # react-native-google-places-api iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for React Native Apps From 7798b5b18a07325273ce7d70b4e863c0641ba5df Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 20:20:45 +0800 Subject: [PATCH 11/26] Brought back locationRestriction and locationBias Fixing 0cb4a39350b262afa7e4c8a6ad71b6a31908bdda --- ios/RNGooglePlaces.h | 3 +-- ios/RNGooglePlaces.m | 26 +++++--------------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/ios/RNGooglePlaces.h b/ios/RNGooglePlaces.h index 006d2b0..c5fe3c6 100644 --- a/ios/RNGooglePlaces.h +++ b/ios/RNGooglePlaces.h @@ -10,7 +10,6 @@ - (GMSPlacesAutocompleteTypeFilter) getFilterType:(NSString *)type; - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boolean)currentOrFetch; -/// TODO: 5.1.0 Update -// - (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions; +- (void) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions filter: (GMSAutocompleteFilter *)autocompleteFilter; @end diff --git a/ios/RNGooglePlaces.m b/ios/RNGooglePlaces.m index 0189fd1..c873b18 100644 --- a/ios/RNGooglePlaces.m +++ b/ios/RNGooglePlaces.m @@ -13,8 +13,6 @@ @interface RNGooglePlaces() @property (strong, nonatomic) CLLocationManager *locationManager; -/// TODO: 5.1.0 Update -// @property GMSAutocompleteBoundsMode boundsMode; @end @@ -41,9 +39,6 @@ - (instancetype)init _instance = self; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; - - /// TODO: 5.1.0 Update - /// self.boundsMode = kGMSAutocompleteBoundsModeBias; } return self; @@ -67,8 +62,7 @@ - (void)dealloc NSDictionary *locationBias = [RCTConvert NSDictionary:options[@"locationBias"]]; NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]]; - /// TODO: 5.1.0 Update - /// GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; + [self getBounds:locationBias andRestrictOptions:locationRestriction filter:autocompleteFilter]; GMSAutocompleteSessionToken *token = [[GMSAutocompleteSessionToken alloc] init]; @@ -246,9 +240,8 @@ - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boo return GMSPlaceFieldAll; } -/// TODO: 5.1.0 Update -/* -- (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions + +- (void) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions filter: (GMSAutocompleteFilter *)autocompleteFilter { double biasLatitudeSW = [[RCTConvert NSNumber:biasOptions[@"latitudeSW"]] doubleValue]; double biasLongitudeSW = [[RCTConvert NSNumber:biasOptions[@"longitudeSW"]] doubleValue]; @@ -263,26 +256,17 @@ - (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOpti if (biasLatitudeSW != 0 && biasLongitudeSW != 0 && biasLatitudeNE != 0 && biasLongitudeNE != 0) { CLLocationCoordinate2D neBoundsCorner = CLLocationCoordinate2DMake(biasLatitudeNE, biasLongitudeNE); CLLocationCoordinate2D swBoundsCorner = CLLocationCoordinate2DMake(biasLatitudeSW, biasLongitudeSW); - GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:neBoundsCorner - coordinate:swBoundsCorner]; - return bounds; + autocompleteFilter.locationBias = GMSPlaceRectangularLocationOption(neBoundsCorner, swBoundsCorner); } if (restrictLatitudeSW != 0 && restrictLongitudeSW != 0 && restrictLatitudeNE != 0 && restrictLongitudeNE != 0) { CLLocationCoordinate2D neBoundsCorner = CLLocationCoordinate2DMake(restrictLatitudeNE, restrictLongitudeNE); CLLocationCoordinate2D swBoundsCorner = CLLocationCoordinate2DMake(restrictLatitudeSW, restrictLongitudeSW); - GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:neBoundsCorner - coordinate:swBoundsCorner]; - self.boundsMode = kGMSAutocompleteBoundsModeRestrict; - - return bounds; + autocompleteFilter.locationRestriction = GMSPlaceRectangularLocationOption(neBoundsCorner, swBoundsCorner); } - - return nil; } -*/ @end From 4e5d9d538b20604e3c5f18c7b3761e99d349c526 Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 20:21:20 +0800 Subject: [PATCH 12/26] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 70ba211..873a789 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ - This package was updated to use 5.1.0 (Places for iOS SDK) - This won't be regularly updated +- This was also tested using RN 0.63.4 # react-native-google-places-api iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for React Native Apps From b12ec75f10e1489783bbe73590b807f644a8a825 Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 20:31:44 +0800 Subject: [PATCH 13/26] Updated package.json and .podspec --- package.json | 10 +++++----- react-native-google-places.podspec | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index a57c79b..5ba9270 100644 --- a/package.json +++ b/package.json @@ -2,19 +2,19 @@ "name": "react-native-google-places-api", "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", - "author": "Amenulhaq ", - "version": "1.0.2", + "author": "Marq Roldan ", + "version": "1.0.0", "scripts": {}, "repository": { "type": "git", - "url": "git+https://github.com/Amenulhaq/react-native-google-places-api.git" + "url": "git+https://github.com/marqroldan/react-native-google-places-api.git" }, "license": "MIT", "bugs": { - "url": "https://github.com/Amenulhaq/react-native-google-places-api/issues" + "url": "https://github.com/marqroldan/react-native-google-places-api/issues" }, "types": "index.d.ts", - "homepage": "https://github.com/Amenulhaq/react-native-google-places-api#readme", + "homepage": "https://github.com/marqroldan/react-native-google-places-api/blob/master/README.md", "keywords": [ "react", "react-native", diff --git a/react-native-google-places.podspec b/react-native-google-places.podspec index cc0133d..376380d 100644 --- a/react-native-google-places.podspec +++ b/react-native-google-places.podspec @@ -8,8 +8,8 @@ Pod::Spec.new do |s| s.description = package['description'] s.license = package['license'] s.author = package['author'] - s.homepage = 'https://github.com/Amenulhaq/react-native-google-places-api' - s.source = { :git => 'https://github.com/Amenulhaq/react-native-google-places-api.git', :tag => s.version } + s.homepage = 'https://github.com/marqroldan/react-native-google-places-api' + s.source = { :git => 'https://github.com/marqroldan/react-native-google-places-api.git', :tag => s.version } s.platform = :ios, '11.0' From 3b346ccc16245dd97d3402de4e4d439f4d40399c Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 20:45:34 +0800 Subject: [PATCH 14/26] Updated packaged name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5ba9270..3318034 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "react-native-google-places-api", + "name": "@marqroldan/react-native-google-places-api", "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", "author": "Marq Roldan ", From 5cd6bd0a43c1cf8f95a21e80001f9b355b41b42c Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 21:02:54 +0800 Subject: [PATCH 15/26] Added note about the autocomplete modal --- README.md | 245 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 140 insertions(+), 105 deletions(-) diff --git a/README.md b/README.md index 873a789..5e73053 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,15 @@ - This package was updated to use 5.1.0 (Places for iOS SDK) - This won't be regularly updated - This was also tested using RN 0.63.4 +- Does **not** have the autocomplete modal (b572c5464ca35500001dcae6532c209670813312) # react-native-google-places-api + iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for React Native Apps ### **Notice: The Google Play Services version of the Places SDK for Android (in Google Play Services 16.0.0) is deprecated as of January 29, 2019, and will be turned off on July 29, 2019. A new version of the Places SDK for Android is now available. I suggest you read the documentations again and update your app to use v3.0.1 (or above) of this package** -### Also support dark mode for iOS 13 and above ** +### Also support dark mode for iOS 13 and above \*\* ## Shots @@ -21,15 +23,16 @@ iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for Reac ## Versioning: + - for RN >= 0.40.0, use v3+ (e.g. react-native-google-places-api@1.0.2) - If you are still using the v2 of this library, you really should not, then **[Version 2 Documentations](/READMEV2.md)** - ## Install ``` npm i react-native-google-places-api --save ``` + OR ``` @@ -37,6 +40,7 @@ yarn add react-native-google-places-api ``` #### Google Places API Set-Up + 1. Sign up for [Google Places & Google Maps APIs for Android in Google API Console](https://cloud.google.com/maps-platform/#get-started) to grab your Android API key (not browser key). 2. Read further API setup guides at [https://developers.google.com/places/android-sdk/signup](https://developers.google.com/places/android-sdk/signup). 3. Similarly, sign up for [Google Places API for iOS in Google API Console](https://cloud.google.com/maps-platform/#get-started) to grab your iOS API key (not browser key). @@ -47,6 +51,7 @@ yarn add react-native-google-places-api #### Post-Install Steps (iOS) ##### 1) Auto Linking & Cocoapods Integration + - If you do not have CocoaPods already installed on your machine, run `gem install cocoapods` to set it up the first time. (Hint: Go grab a cup of coffee!) - If you are not using Cocoapods in your project already, run `cd ios && pod init` at the root directory of your project. This would create a `Podfile` in your `ios` directory. - Run `react-native link react-native-google-places-api` at the root directory of your project and ensure you edit your Podfile to look like the sample below (remove all the targets you are not building for, such as Tests and tvOS): @@ -100,12 +105,16 @@ end - Close Xcode, and then open (double-click) your project's .xcworkspace file to launch Xcode. From this time onwards, you must use the `.xcworkspace` file to open the project. Or just use the `react-native run-ios` command as usual to run your app in the simulator. ##### 2) Configuration on iOS -- In your `AppDelegate.m` file, import the Google Places library by adding + +- In your `AppDelegate.m` file, import the Google Places library by adding + ```objectivec - @import GooglePlaces; + @import GooglePlaces; @import GoogleMaps; ``` + on top of the file. + - Within the `didFinishLaunchingWithOptions` method, instantiate the library as follows - **read about a better way to secure this below**: ```objectivec @@ -113,7 +122,7 @@ on top of the file. [GMSServices provideAPIKey:@"YOUR_IOS_API_KEY_HERE"]; ``` -- Ensure you have the required location permissions for the application by declaring keys for `NSLocationWhenInUseUsageDescription` and `NSLocationAlwaysAndWhenInUseUsageDescription` in your `info.plist` file, either using Xcode or manually editing the file e.g. +- Ensure you have the required location permissions for the application by declaring keys for `NSLocationWhenInUseUsageDescription` and `NSLocationAlwaysAndWhenInUseUsageDescription` in your `info.plist` file, either using Xcode or manually editing the file e.g. ```plist NSLocationWhenInUseUsageDescription @@ -122,10 +131,10 @@ on top of the file. RNGPDemos needs your location to show you places ``` - #### Post-Install Steps (Android) ##### Auto Linking With Your Project + - This was done automatically for you when you ran `react-native link react-native-google-places-api`. Or you can run the command now if you have not already. - In your `AndroidManifest.xml` file, request the following permissions: @@ -142,6 +151,7 @@ RNGP_ANDROID_API_KEY=Insert_API_KEY_here ``` ##### Manual Linking With Your Project (Android) + - The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places-api`. Otherwise, do the following or just ensure they are in place; - Add the following in your `android/settings.gradle` file: @@ -149,6 +159,7 @@ RNGP_ANDROID_API_KEY=Insert_API_KEY_here include ':react-native-google-places-api' project(':react-native-google-places-api').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places-api/android') ``` + - Add the following in your `android/app/build.grade` file: ```groovy @@ -169,7 +180,7 @@ allprojects { url "$rootDir/../node_modules/react-native/android" } maven { - url "https://maven.google.com" + url "https://maven.google.com" } } } @@ -208,33 +219,30 @@ android { } ``` - - Finally, we can run `react-native run-android` to get started. - ## Usage -### Allows your users to enter place names and addresses - and autocompletes your users' queries as they type. +### Allows your users to enter place names and addresses - and autocompletes your users' queries as they type. #### Import library ```javascript -import RNGooglePlaces from 'react-native-google-places-api'; +import RNGooglePlaces from "react-native-google-places-api"; ``` #### Open Autocomplete Modal (e.g as Callback to an onPress event) - ```javascript 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 + .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() { @@ -253,102 +261,123 @@ class GPlacesDemo extends Component { ``` ##### **Optional Parameters** + To customize autocomplete results as listed for [Android](https://developers.google.com/places/android-sdk/autocomplete) and [iOS](https://developers.google.com/places/ios-sdk/autocomplete) in the official docs, you can pass an `options` object as a parameter to the `openAutocompleteModal()` method as follows: ```javascript - RNGooglePlaces.openAutocompleteModal({ - initialQuery: 'vestar', - locationRestriction: { - latitudeSW: 6.3670553, - longitudeSW: 2.7062895, - latitudeNE: 6.6967964, - longitudeNE: 4.351055 - }, - country: 'NG', - type: 'establishment' - }, ['placeID', 'location', 'name', 'address', 'types', 'openingHours', 'plusCode', 'rating', 'userRatingsTotal', 'viewport'] - ) - .then((place) => { - console.log(place); - }) - .catch(error => console.log(error.message)); +RNGooglePlaces.openAutocompleteModal( + { + initialQuery: "vestar", + locationRestriction: { + latitudeSW: 6.3670553, + longitudeSW: 2.7062895, + latitudeNE: 6.6967964, + longitudeNE: 4.351055, + }, + country: "NG", + type: "establishment", + }, + [ + "placeID", + "location", + "name", + "address", + "types", + "openingHours", + "plusCode", + "rating", + "userRatingsTotal", + "viewport", + ] +) + .then((place) => { + console.log(place); + }) + .catch((error) => console.log(error.message)); ``` + **OPTIONS** -- **`type`** _(String)_ - The type of results to return. Can only 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](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (case insensitive). If this is not set, no country filtering will take place. *(optional)* -- **`locationBias`** _(Object)_ - To bias autocomplete results to a specific geographic region, pass an object (with the keys: `latitudeNE` _(Number)_, `longitudeNE` _(Number)_, `latitudeSW` _(Number)_, `longitudeSW` _(Number)_) representing the bounding box for the region. *(optional)* -- **`locationRestriction`** _(Object)_ - To restrict autocomplete results to a specific geographic region, pass an object (with the keys: `latitudeNE` _(Number)_, `longitudeNE` _(Number)_, `latitudeSW` _(Number)_, `longitudeSW` _(Number)_) representing the bounding box for the region. *(optional)* + +- **`type`** _(String)_ - The type of results to return. Can only 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](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (case insensitive). If this is not set, no country filtering will take place. _(optional)_ +- **`locationBias`** _(Object)_ - To bias autocomplete results to a specific geographic region, pass an object (with the keys: `latitudeNE` _(Number)_, `longitudeNE` _(Number)_, `latitudeSW` _(Number)_, `longitudeSW` _(Number)_) representing the bounding box for the region. _(optional)_ +- **`locationRestriction`** _(Object)_ - To restrict autocomplete results to a specific geographic region, pass an object (with the keys: `latitudeNE` _(Number)_, `longitudeNE` _(Number)_, `latitudeSW` _(Number)_, `longitudeSW` _(Number)_) representing the bounding box for the region. _(optional)_ - **`useOverlay`** _(Boolean)_ [Android Only] - If true, the autocomplete modal will open as an [overlay rather than fullscreen](https://developers.google.com/places/images/acw_overlay.png). Defaults to `false`. -- **`initialQuery`** _(String)_ [Android Only] - If present, the autocomplete modal would launch with results pre-populated for the query passed *(optional)*. +- **`initialQuery`** _(String)_ [Android Only] - If present, the autocomplete modal would launch with results pre-populated for the query passed _(optional)_. **NOTE** - On iOS, only one of `locationBias` or `locationRestriction` is respected, when passing both, only the first passed option would be used. **PLACE FIELDS** -- To prevent yourself from incurring huge usage bill, you can select the result fields you need in your application. Pass an *(optional)* `placeFields` as the second param to `openAutocompleteModal`. + +- To prevent yourself from incurring huge usage bill, you can select the result fields you need in your application. Pass an _(optional)_ `placeFields` as the second param to `openAutocompleteModal`. - **placeFields** is an **`Array`** of `String` such as `placeID`, `location`, `name`, `address`, `types`, `openingHours`, `plusCode`, `rating`, `userRatingsTotal`, `viewport`, `website`, `phoneNumber`, `plusCode` and `addressComponents` _(available in v3.0.1+)_. - Defaults to an empty array which returns every field possible for the particular place. - #### Example Response from the Autocomplete Modal + ```javascript { priceLevel: 0, - viewport: { + viewport: { longitudeSW: 3.320172219708498, latitudeSW: 6.572546249999999, longitudeNE: 3.322870180291502, - latitudeNE: 6.584909250000001 + latitudeNE: 6.584909250000001 }, address: 'Lagos, Nigeria', - location: { - longitude: 3.3211348, - latitude: 6.5818185 + location: { + longitude: 3.3211348, + latitude: 6.5818185 }, - addressComponents: [ + addressComponents: [ { shortName: 'Lagos', name: 'Lagos', - types: [ 'locality', 'political' ] + types: [ 'locality', 'political' ] }, { shortName: 'LA', name: 'Lagos', - types: [ 'administrative_area_level_1', 'political' ] + types: [ 'administrative_area_level_1', 'political' ] }, { shortName: 'NG', name: 'Nigeria', - types: [ 'country', 'political' ] - } + types: [ 'country', 'political' ] + } ], userRatingsTotal: 939, - plusCode: { + plusCode: { globalCode: '6FR5H8JC+PF', - compoundCode: 'H8JC+PF Lagos, Nigeria' + compoundCode: 'H8JC+PF Lagos, Nigeria' }, rating: 3.2, types: [ 'airport', 'point_of_interest', 'establishment' ], attributions: [], placeID: 'ChIJhRTXUeeROxARmk_Rp3PtIvI', - name: 'Murtala Muhammed International Airport' + name: 'Murtala Muhammed International Airport' } ``` + - Note: The keys available from the response from the resolved `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. ### Get Current Place + 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. Ensure you have required the appropriate permissions, as stated post-install steps above, before making this request. ```javascript - RNGooglePlaces.getCurrentPlace() - .then((results) => console.log(results)) - .catch((error) => console.log(error.message)); +RNGooglePlaces.getCurrentPlace() + .then((results) => console.log(results)) + .catch((error) => console.log(error.message)); ``` OR ```javascript - RNGooglePlaces.getCurrentPlace(['placeID', 'location', 'name', 'address']) - .then((results) => console.log(results)) - .catch((error) => console.log(error.message)); +RNGooglePlaces.getCurrentPlace(["placeID", "location", "name", "address"]) + .then((results) => console.log(results)) + .catch((error) => console.log(error.message)); ``` + **PLACE FIELDS** -- To prevent yourself from incurring huge usage bill, you can select the result fields you need in your application. Pass an *(optional)* `placeFields` as the only param to `getCurrentPlace`. + +- To prevent yourself from incurring huge usage bill, you can select the result fields you need in your application. Pass an _(optional)_ `placeFields` as the only param to `getCurrentPlace`. - **placeFields** is an **`Array`** of `String` such as `placeID`, `location`, `name`, `address`, `types`, `openingHours`, `plusCode`, `rating`, `userRatingsTotal`, `viewport`. - Defaults to an empty array which returns every field possible for the particular place. - Place note that requesting for `website`, `phoneNumber`, `phoneNumber` and `addressComponents` are not supported when calling `getCurrentPlace`. @@ -374,57 +403,57 @@ OR 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. ### Using Your Own Custom UI/Views + 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`. #### Get Autocomplete Predictions ```javascript - RNGooglePlaces.getAutocompletePredictions('facebook') - .then((results) => this.setState({ predictions: results })) - .catch((error) => console.log(error.message)); +RNGooglePlaces.getAutocompletePredictions("facebook") + .then((results) => this.setState({ predictions: results })) + .catch((error) => console.log(error.message)); ``` ##### **Optional Parameters** + To filter autocomplete results as listed for [Android](https://developers.google.com/places/android-api/autocomplete#restrict_autocomplete_results) and [iOS](https://developers.google.com/places/ios-api/autocomplete#call_gmsplacesclient) in the official docs, you can pass an `options` object as a second parameter to the `getAutocompletePredictions()` method as follows: ```javascript - RNGooglePlaces.getAutocompletePredictions('Lagos', { - type: 'cities', - country: 'NG' - }) - .then((place) => { +RNGooglePlaces.getAutocompletePredictions("Lagos", { + type: "cities", + country: "NG", +}) + .then((place) => { console.log(place); - }) - .catch(error => console.log(error.message)); + }) + .catch((error) => console.log(error.message)); ``` + OR ```javascript -RNGooglePlaces.getAutocompletePredictions('pizza', { - type: 'establishments', - locationBias: { - latitudeSW: 6.3670553, - longitudeSW: 2.7062895, - latitudeNE: 6.6967964, - longitudeNE: 4.351055 - } - }) - .then((place) => { +RNGooglePlaces.getAutocompletePredictions("pizza", { + type: "establishments", + locationBias: { + latitudeSW: 6.3670553, + longitudeSW: 2.7062895, + latitudeNE: 6.6967964, + longitudeNE: 4.351055, + }, +}) + .then((place) => { console.log(place); - }) - .catch(error => console.log(error.message)); + }) + .catch((error) => console.log(error.message)); ``` - -- **`type`** _(String)_ - The type of results to return. Can only 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](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (case insensitive). If this is not set, no country filtering will take place. *(optional)* -- **`locationBias`** _(Object)_ - To bias autocomplete results to a specific geographic region, pass an object (with the keys: `latitudeNE` _(Number)_, `longitudeNE` _(Number)_, `latitudeSW` _(Number)_, `longitudeSW` _(Number)_) representing the bounding box for the region. *(optional)* -- **`locationRestriction`** _(Object)_ - To restrict autocomplete results to a specific geographic region, pass an object (with the keys: `latitudeNE` _(Number)_, `longitudeNE` _(Number)_, `latitudeSW` _(Number)_, `longitudeSW` _(Number)_) representing the bounding box for the region. *(optional)* +- **`type`** _(String)_ - The type of results to return. Can only 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](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (case insensitive). If this is not set, no country filtering will take place. _(optional)_ +- **`locationBias`** _(Object)_ - To bias autocomplete results to a specific geographic region, pass an object (with the keys: `latitudeNE` _(Number)_, `longitudeNE` _(Number)_, `latitudeSW` _(Number)_, `longitudeSW` _(Number)_) representing the bounding box for the region. _(optional)_ +- **`locationRestriction`** _(Object)_ - To restrict autocomplete results to a specific geographic region, pass an object (with the keys: `latitudeNE` _(Number)_, `longitudeNE` _(Number)_, `latitudeSW` _(Number)_, `longitudeSW` _(Number)_) representing the bounding box for the region. _(optional)_ **NOTE** - On iOS, only one of `locationBias` or `locationRestriction` is respected, when passing both, only the first passed option would be used. - - #### Example Response from Calling getAutocompletePredictions() ```javascript @@ -446,21 +475,27 @@ RNGooglePlaces.getAutocompletePredictions('pizza', { #### Look-Up Place By ID ```javascript - RNGooglePlaces.lookUpPlaceByID('ChIJZa6ezJa8j4AR1p1nTSaRtuQ') - .then((results) => console.log(results)) - .catch((error) => console.log(error.message)); +RNGooglePlaces.lookUpPlaceByID("ChIJZa6ezJa8j4AR1p1nTSaRtuQ") + .then((results) => console.log(results)) + .catch((error) => console.log(error.message)); ``` + OR ```javascript - RNGooglePlaces.lookUpPlaceByID('ChIJZa6ezJa8j4AR1p1nTSaRtuQ', ['placeID', 'location', 'name', 'address']) - .then((results) => console.log(results)) - .catch((error) => console.log(error.message)); +RNGooglePlaces.lookUpPlaceByID("ChIJZa6ezJa8j4AR1p1nTSaRtuQ", [ + "placeID", + "location", + "name", + "address", +]) + .then((results) => console.log(results)) + .catch((error) => console.log(error.message)); ``` - **PLACE FIELDS** -- To prevent yourself from incurring huge usage bill, you can select the result fields you need in your application. Pass an *(optional)* `placeFields` as the second param to `lookUpPlaceByID`. + +- To prevent yourself from incurring huge usage bill, you can select the result fields you need in your application. Pass an _(optional)_ `placeFields` as the second param to `lookUpPlaceByID`. - **placeFields** is an **`Array`** of `String` such as `placeID`, `location`, `name`, `address`, `types`, `openingHours`, `plusCode`, `rating`, `userRatingsTotal`, `viewport`, `addressComponents`, `website`, `phoneNumber`, and `phoneNumber`. - Defaults to an empty array which returns every field possible for the particular place. @@ -477,12 +512,15 @@ OR phoneNumber: '+1 650-543-4800', } ``` + - Note: Check Autocomplete response for notes and other available keys. #### Design Hint + 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. #### PS (from Google) + - Use of the `getAutocompletePredictions()` method is subject to tiered query limits. See the documentation on [Android](https://developers.google.com/places/android-api/usage) & [iOS](https://developers.google.com/places/ios-api/usage) Usage Limits. - Also, your UI must either display a 'Powered by Google' attribution, or appear within a Google-branded map. @@ -490,12 +528,13 @@ The typical use flow would be to call `getAutocompletePredictions()` when the va #### Android API Key -- From version 3 of this package, on Android, the package would, by default, first look for your API key in `System Variables` before checking for it in your `gradle.properties` file - this ensures you can totally keep your keys out of `Version Control`. +- From version 3 of this package, on Android, the package would, by default, first look for your API key in `System Variables` before checking for it in your `gradle.properties` file - this ensures you can totally keep your keys out of `Version Control`. - Remove your API key from `gradle.properties`, if already defined. Define a system variable representing your Android API key e.g. on a Unix/Mac terminal run: ```bash export RNGP_ANDROID_API_KEY=Insert_API_KEY_here ``` + - You may need to export this system/environment variable before every build or add them to your `~/.bash_profile` file or similar files. - Ensure you have the system/environment variable replicated in your `CI/CD` build and you should be fine. - You may skip these steps and continue to have your API key in `gradle.properties`, things would work just as fine. @@ -540,10 +579,9 @@ end - Replace the string versions of your key in your `AppDelegate.m` file. - You may skip these steps and continue to have your API key directly in `AppDelegate.m`, things would work just as fine. - ### Troubleshooting -Ensure you have automatically/manually linked dependencies and/or re-run the build after doing so. +Ensure you have automatically/manually linked dependencies and/or re-run the build after doing so. 1. Run `react-native link` 2. Try `Manual Linking With Your Project` steps above. @@ -551,9 +589,6 @@ Ensure you have automatically/manually linked dependencies and/or re-run the bui On iOS, ensure you have installed the native dependencies with Cocoapods. - ## License -The MIT License. - - +The MIT License. From 8d8d73807e9cee33bd6d5c6f009b6f3ec3b07e49 Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 21:11:42 +0800 Subject: [PATCH 16/26] Fixed package name --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 3318034..bb68e4e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@marqroldan/react-native-google-places-api", + "name": "react-native-google-places-native", "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", "author": "Marq Roldan ", @@ -7,14 +7,14 @@ "scripts": {}, "repository": { "type": "git", - "url": "git+https://github.com/marqroldan/react-native-google-places-api.git" + "url": "git+https://github.com/marqroldan/react-native-google-places-native.git" }, "license": "MIT", "bugs": { - "url": "https://github.com/marqroldan/react-native-google-places-api/issues" + "url": "https://github.com/marqroldan/react-native-google-places-native/issues" }, "types": "index.d.ts", - "homepage": "https://github.com/marqroldan/react-native-google-places-api/blob/master/README.md", + "homepage": "https://github.com/marqroldan/react-native-google-places-native/blob/master/README.md", "keywords": [ "react", "react-native", From 9f86c47361c3ec76a0c59ddfae2192a01a1c202d Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Wed, 26 Jan 2022 21:12:00 +0800 Subject: [PATCH 17/26] Updated package name --- .gitignore | 2 +- README.md | 26 +-- READMEV2.md | 272 ++++++++++++++++------------- index.d.ts | 208 +++++++++++----------- react-native-google-places.podspec | 4 +- 5 files changed, 271 insertions(+), 241 deletions(-) diff --git a/.gitignore b/.gitignore index e4ca1d7..8bb8459 100644 --- a/.gitignore +++ b/.gitignore @@ -55,7 +55,7 @@ project.xcworkspace # Android/IJ # -react-native-google-places-api.iml +react-native-google-places-native.iml .idea .gradle .vscode diff --git a/README.md b/README.md index 5e73053..4e4f67f 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - This was also tested using RN 0.63.4 - Does **not** have the autocomplete modal (b572c5464ca35500001dcae6532c209670813312) -# react-native-google-places-api +# react-native-google-places-native iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for React Native Apps @@ -24,19 +24,19 @@ iOS/Android Google Places Widgets (Autocomplete Modal) and API Services for Reac ## Versioning: -- for RN >= 0.40.0, use v3+ (e.g. react-native-google-places-api@1.0.2) +- for RN >= 0.40.0, use v3+ (e.g. react-native-google-places-native@1.0.2) - If you are still using the v2 of this library, you really should not, then **[Version 2 Documentations](/READMEV2.md)** ## Install ``` -npm i react-native-google-places-api --save +npm i react-native-google-places-native --save ``` OR ``` -yarn add react-native-google-places-api +yarn add react-native-google-places-native ``` #### Google Places API Set-Up @@ -54,7 +54,7 @@ yarn add react-native-google-places-api - If you do not have CocoaPods already installed on your machine, run `gem install cocoapods` to set it up the first time. (Hint: Go grab a cup of coffee!) - If you are not using Cocoapods in your project already, run `cd ios && pod init` at the root directory of your project. This would create a `Podfile` in your `ios` directory. -- Run `react-native link react-native-google-places-api` at the root directory of your project and ensure you edit your Podfile to look like the sample below (remove all the targets you are not building for, such as Tests and tvOS): +- Run `react-native link react-native-google-places-native` at the root directory of your project and ensure you edit your Podfile to look like the sample below (remove all the targets you are not building for, such as Tests and tvOS): ```ruby # platform :ios, '9.0' @@ -82,13 +82,13 @@ target '_YOUR_PROJECT_TARGET_' do pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' # This should already be auto-added for you, if not add the line below - pod 'react-native-google-places-api', :path => '../node_modules/react-native-google-places-api' + pod 'react-native-google-places-native', :path => '../node_modules/react-native-google-places-native' end post_install do |installer| installer.pods_project.targets.each do |target| - if target.name == 'react-native-google-places-api' + if target.name == 'react-native-google-places-native' target.build_configurations.each do |config| config.build_settings['CLANG_ENABLE_MODULES'] = 'No' end @@ -135,7 +135,7 @@ on top of the file. ##### Auto Linking With Your Project -- This was done automatically for you when you ran `react-native link react-native-google-places-api`. Or you can run the command now if you have not already. +- This was done automatically for you when you ran `react-native link react-native-google-places-native`. Or you can run the command now if you have not already. - In your `AndroidManifest.xml` file, request the following permissions: ```xml @@ -152,12 +152,12 @@ RNGP_ANDROID_API_KEY=Insert_API_KEY_here ##### Manual Linking With Your Project (Android) -- The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places-api`. Otherwise, do the following or just ensure they are in place; +- The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places-native`. Otherwise, do the following or just ensure they are in place; - Add the following in your `android/settings.gradle` file: ```groovy -include ':react-native-google-places-api' -project(':react-native-google-places-api').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places-api/android') +include ':react-native-google-places-native' +project(':react-native-google-places-native').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places-native/android') ``` - Add the following in your `android/app/build.grade` file: @@ -165,7 +165,7 @@ project(':react-native-google-places-api').projectDir = new File(rootProject.pro ```groovy dependencies { ... - compile project(':react-native-google-places-api') + compile project(':react-native-google-places-native') } ``` @@ -228,7 +228,7 @@ android { #### Import library ```javascript -import RNGooglePlaces from "react-native-google-places-api"; +import RNGooglePlaces from "react-native-google-places-native"; ``` #### Open Autocomplete Modal (e.g as Callback to an onPress event) diff --git a/READMEV2.md b/READMEV2.md index 409c588..07e4726 100644 --- a/READMEV2.md +++ b/READMEV2.md @@ -1,11 +1,12 @@ -# react-native-google-places-api +# react-native-google-places-native + iOS/Android Google Places Widgets (Autocomplete, Place Picker) and API Services for React Native Apps ### **Notice: The Google Play Services version of the Places SDK for Android (in Google Play Services 16.0.0) is deprecated as of January 29, 2019, and will be turned off on July 29, 2019. A new version of the Places SDK for Android is now available.** ### I recommend you migrate your applications to the version 3.0.1 (or above) of this package - Heads up! There are tons of breaking changes in the new release. **[Visit the updated README to get started](/README.md)** -### Also support dark mode for iOS 13 and above ** +### Also support dark mode for iOS 13 and above \*\* ## Shots @@ -17,26 +18,27 @@ iOS/Android Google Places Widgets (Autocomplete, Place Picker) and API Services ## Versioning: -- for RN >= 0.40.0, use v2+ (e.g. react-native-google-places-api@1.0.2) -### I recommend you migrate your applications to the version 3.0.1 (or above) of this package - Heads up! There are tons of breaking changes in the new release. **[Visit the updated README to get started](/README.md)** +- for RN >= 0.40.0, use v2+ (e.g. react-native-google-places-native@1.0.2) +### I recommend you migrate your applications to the version 3.0.1 (or above) of this package - Heads up! There are tons of breaking changes in the new release. **[Visit the updated README to get started](/README.md)** ## Install ``` -npm i react-native-google-places-api --save -react-native link react-native-google-places-api +npm i react-native-google-places-native --save +react-native link react-native-google-places-native ``` + OR ``` -yarn add react-native-google-places-api -react-native link react-native-google-places-api +yarn add react-native-google-places-native +react-native link react-native-google-places-native ``` - #### Google Places API Set-Up + 1. Sign up for [Google Places API for Android in Google API Console](https://console.developers.google.com/flows/enableapi?apiid=placesandroid&reusekey=true) to grab your Android API key (not browser key). 2. Read further API setup guides at [https://developers.google.com/places/android-api/signup](https://developers.google.com/places/android-api/signup). 3. Similarly, sign up for [Google Places API for iOS in Google API Console](https://console.developers.google.com/flows/enableapi?apiid=placesios&reusekey=true) to grab your iOS API key (not browser key). @@ -48,14 +50,17 @@ react-native link react-native-google-places-api ##### iOS (requires CocoaPods) ##### Auto Linking With Your Project (iOS & Android) -- This was done automatically for you when you ran `react-native link react-native-google-places-api`. Or you can run the command now if you have not already. + +- This was done automatically for you when you ran `react-native link react-native-google-places-native`. Or you can run the command now if you have not already. ##### Manual Linking With Your Project (iOS) + - In XCode, in the project navigator, right click `Libraries ➜ Add Files to [your project's name]`. -- Go to `node_modules` ➜ `react-native-google-places-api` and add `RNGooglePlaces.xcodeproj`. +- Go to `node_modules` ➜ `react-native-google-places-native` and add `RNGooglePlaces.xcodeproj`. - In XCode, in the project navigator, select your project. Add `libRNGooglePlaces.a` to your project's `Build Phases` ➜ `Link Binary With Libraries`. ##### Install CocoaPods Dependencies + - If you do not have CocoaPods already installed on your machine, run `gem install cocoapods` to set it up the first time. (Hint: Go grab a cup of coffee!) - If you are not using Cocoapods in your project already, run `cd ios && pod init` at the root directory of your project. - Add `pod 'GooglePlaces'`, `pod 'GooglePlacePicker'` and `pod 'GoogleMaps'` to your Podfile. Otherwise just edit your Podfile to include: @@ -71,6 +76,7 @@ target 'YOUR_APP_TARGET_NAME' do end ``` + - In your AppDelegate.m file, import the Google Places library by adding `@import GooglePlaces;` and `@import GoogleMaps;` on top of the file. - Within the `didFinishLaunchingWithOptions` method, instantiate the library as follows: @@ -78,10 +84,12 @@ end [GMSPlacesClient provideAPIKey:@"YOUR_IOS_API_KEY_HERE"]; [GMSServices provideAPIKey:@"YOUR_IOS_API_KEY_HERE"]; ``` + - By now, you should be all set to install the packages from your Podfile. Run `pod install` from your `ios` directory. - Close Xcode, and then open (double-click) your project's .xcworkspace file to launch Xcode. From this time onwards, you must use the `.xcworkspace` file to open the project. Or just use the `react-native run-ios` command as usual to run your app in the simulator. ##### Android + - In your AndroidManifest.xml file, request location permissions and add your API key in a meta-data tag (ensure you are within the `` tag as follows: ```xml @@ -95,20 +103,23 @@ end ... ``` + ##### Manual Linking With Your Project (Android) -- The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places-api`. Otherwise, do the following or just ensure they are in place; + +- The following additional setup steps are optional as they should have been taken care of, for you when you ran `react-native link react-native-google-places-native`. Otherwise, do the following or just ensure they are in place; - Add the following in your `android/settings.gradle` file: ```groovy -include ':react-native-google-places-api' -project(':react-native-google-places-api').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places-api/android') +include ':react-native-google-places-native' +project(':react-native-google-places-native').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-places-native/android') ``` + - Add the following in your `android/app/build.grade` file: ```groovy dependencies { ... - compile project(':react-native-google-places-api') + compile project(':react-native-google-places-native') } ``` @@ -123,7 +134,7 @@ allprojects { url "$rootDir/../node_modules/react-native/android" } maven { - url "https://maven.google.com" + url "https://maven.google.com" } } } @@ -143,14 +154,14 @@ protected List getPackages() { ); } ``` -- Finally, we can run `react-native run-android` to get started. +- Finally, we can run `react-native run-android` to get started. ##### Configuring Versions for Dependencies (Optional & for Android Only) - Option 1: Use Project-Wide Gradle Config: -You can define *[project-wide properties](https://developer.android.com/studio/build/gradle-tips.html)* (**recommended**) in your root `/android/build.gradle`, and let the library auto-detect the presence of the following properties: +You can define _[project-wide properties](https://developer.android.com/studio/build/gradle-tips.html)_ (**recommended**) in your root `/android/build.gradle`, and let the library auto-detect the presence of the following properties: ```groovy buildscript {...} @@ -171,13 +182,13 @@ You can define *[project-wide properties](https://developer.android.com/studio/b - Option 2: Use Specific Gradle Config: -If you do **not** have *project-wide properties* defined or want to use a different Google Play-Services version than the one included in this library (shown above), use the following instead (switch 11.6.2 for the desired version): +If you do **not** have _project-wide properties_ defined or want to use a different Google Play-Services version than the one included in this library (shown above), use the following instead (switch 11.6.2 for the desired version): ```groovy ... dependencies { ... - compile(project(':react-native-google-places-api')){ + compile(project(':react-native-google-places-native')){ 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' @@ -188,30 +199,28 @@ If you do **not** have *project-wide properties* defined or want to use a differ } ``` - ## Usage -### Allows your users to enter place names and addresses - and autocompletes your users' queries as they type. +### Allows your users to enter place names and addresses - and autocompletes your users' queries as they type. #### Import library ```javascript -import RNGooglePlaces from 'react-native-google-places-api'; +import RNGooglePlaces from "react-native-google-places-native"; ``` #### Open Autocomplete Modal (e.g as Callback to an onPress event) - ```javascript 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 + .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() { @@ -230,40 +239,42 @@ class GPlacesDemo extends Component { ``` ##### **Optional Parameters** + To filter autocomplete results as listed for [Android](https://developers.google.com/places/android-api/autocomplete#restrict_autocomplete_results) and [iOS](https://developers.google.com/places/ios-api/autocomplete#call_gmsplacesclient) in the official docs, you can pass an `options` object as a parameter to the `openAutocompleteModal()` method as follows: ```javascript - RNGooglePlaces.openAutocompleteModal({ - type: 'establishment', - country: 'CA', - latitude: 53.544389, - longitude: -113.490927, - radius: 10 - }) - .then((place) => { +RNGooglePlaces.openAutocompleteModal({ + type: "establishment", + country: "CA", + latitude: 53.544389, + longitude: -113.490927, + radius: 10, +}) + .then((place) => { console.log(place); - }) - .catch(error => console.log(error.message)); + }) + .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](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (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)* +- **`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](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (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](https://developers.google.com/places/images/acw_overlay.png). Defaults to `false`. ### Open PlacePicker Modal + ```javascript 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 + .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() { @@ -280,27 +291,29 @@ class GPlacesDemo extends Component { } } ``` + 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)* +- **`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. ```javascript - RNGooglePlaces.openPlacePickerModal({ - latitude: 53.544389, - longitude: -113.490927, - radius: 0.01 // 10 meters - }) - .then((place) => { +RNGooglePlaces.openPlacePickerModal({ + latitude: 53.544389, + longitude: -113.490927, + radius: 0.01, // 10 meters +}) + .then((place) => { console.log(place); - }) - .catch(error => console.log(error.message)); + }) + .catch((error) => console.log(error.message)); ``` #### Example Response from the Autocomplete & PlacePicker Modals + ```javascript { placeID: "ChIJZa6ezJa8j4AR1p1nTSaRtuQ", @@ -313,16 +326,19 @@ If no initial viewport is set (no argument is passed to the `openPlacePickerModa longitude: -122.14839939999999 } ``` + - Note: The keys available from the response from the resolved `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. ### Get Current Place + 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. ```javascript - RNGooglePlaces.getCurrentPlace() - .then((results) => console.log(results)) - .catch((error) => console.log(error.message)); +RNGooglePlaces.getCurrentPlace() + .then((results) => console.log(results)) + .catch((error) => console.log(error.message)); ``` + #### Example Response from Calling getCurrentPlace() ```javascript @@ -344,52 +360,53 @@ This method returns to you the place where the device is currently located. That 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. ### Using Your Own Custom UI/Views + 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`. #### Get Autocomplete Predictions ```javascript - RNGooglePlaces.getAutocompletePredictions('facebook') - .then((results) => this.setState({ predictions: results })) - .catch((error) => console.log(error.message)); +RNGooglePlaces.getAutocompletePredictions("facebook") + .then((results) => this.setState({ predictions: results })) + .catch((error) => console.log(error.message)); ``` ##### **Optional Parameters** + To filter autocomplete results as listed for [Android](https://developers.google.com/places/android-api/autocomplete#restrict_autocomplete_results) and [iOS](https://developers.google.com/places/ios-api/autocomplete#call_gmsplacesclient) in the official docs, you can pass an `options` object as a second parameter to the `getAutocompletePredictions()` method as follows: ```javascript - RNGooglePlaces.getAutocompletePredictions('Lagos', { - type: 'cities', - country: 'NG' - }) - .then((place) => { +RNGooglePlaces.getAutocompletePredictions("Lagos", { + type: "cities", + country: "NG", +}) + .then((place) => { console.log(place); - }) - .catch(error => console.log(error.message)); + }) + .catch((error) => console.log(error.message)); ``` + OR ```javascript -RNGooglePlaces.getAutocompletePredictions('pizza', { - type: 'establishments', - latitude: 53.544389, - longitude: -113.490927, - radius: 10 - }) - .then((place) => { +RNGooglePlaces.getAutocompletePredictions("pizza", { + type: "establishments", + latitude: 53.544389, + longitude: -113.490927, + radius: 10, +}) + .then((place) => { console.log(place); - }) - .catch(error => console.log(error.message)); + }) + .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](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (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)* +- **`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](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) (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`. - #### Example Response from Calling getAutocompletePredictions() ```javascript @@ -411,10 +428,11 @@ RNGooglePlaces.getAutocompletePredictions('pizza', { #### Look-Up Place By ID ```javascript - RNGooglePlaces.lookUpPlaceByID('ChIJZa6ezJa8j4AR1p1nTSaRtuQ') - .then((results) => console.log(results)) - .catch((error) => console.log(error.message)); +RNGooglePlaces.lookUpPlaceByID("ChIJZa6ezJa8j4AR1p1nTSaRtuQ") + .then((results) => console.log(results)) + .catch((error) => console.log(error.message)); ``` + #### Example Response from Calling lookUpPlaceByID() ```javascript @@ -432,38 +450,44 @@ RNGooglePlaces.getAutocompletePredictions('pizza', { #### Look-Up Places By IDs (2 or more places at a time) ```javascript - const placeIDs = ['ChIJZa6ezJa8j4AR1p1nTSaRtuQ', 'other_place_id']; - RNGooglePlaces.lookUpPlacesByIDs(placeIDs) - .then((results) => console.log(results)) - .catch((error) => console.log(error.message)); +const placeIDs = ["ChIJZa6ezJa8j4AR1p1nTSaRtuQ", "other_place_id"]; +RNGooglePlaces.lookUpPlacesByIDs(placeIDs) + .then((results) => console.log(results)) + .catch((error) => console.log(error.message)); ``` + #### Example Response from Calling lookUpPlacesByIDs() ```javascript [ - { 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', - types: [ 'street_address', 'geocode' ], - phoneNumber: '+1 650-543-4800', - } -] + { + 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", + types: ["street_address", "geocode"], + phoneNumber: "+1 650-543-4800", + }, +]; ``` + - Note: Check Autocomplete & PlacePicker response for notes and other available keys. #### Design Hint + 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. #### PS (from Google) + - Use of the `getAutocompletePredictions()` method is subject to tiered query limits. See the documentation on [Android](https://developers.google.com/places/android-api/usage) & [iOS](https://developers.google.com/places/ios-api/usage) Usage Limits. - Also, your UI must either display a 'Powered by Google' attribution, or appear within a Google-branded map. ### Troubleshooting #### On iOS + You have to link dependencies and re-run the build: 1. Run `react-native link` @@ -471,34 +495,32 @@ You have to link dependencies and re-run the build: 3. Run `react-native run-ios` #### On Android + 1. Run "android" and make sure every packages is updated. 2. If not installed yet, you have to install the following packages: - - 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: - - ```groovy - ... - dependencies { - ... - compile(project(':react-native-google-places-api')){ - 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:11.6.2' - compile 'com.google.android.gms:play-services-places:11.6.2' - compile 'com.google.android.gms:play-services-location:11.6.2' - } - ``` - -## License -The MIT License. +- 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: + ```groovy + ... + dependencies { + ... + compile(project(':react-native-google-places-native')){ + 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:11.6.2' + compile 'com.google.android.gms:play-services-places:11.6.2' + compile 'com.google.android.gms:play-services-location:11.6.2' + } + ``` +## License +The MIT License. diff --git a/index.d.ts b/index.d.ts index ac58127..e978131 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,8 @@ -declare module "react-native-google-places-api" { +declare module "react-native-google-places-native" { /** * 2D Coordinate bounds for view boxes etc, as defined by the bottom left and * top right corners. - * + * * There isn't a direct correspondence between this type and native types. */ export interface GeoCoordinateBounds { @@ -14,7 +14,7 @@ declare module "react-native-google-places-api" { /** * Standard cross-platform coordinate type. - * + * * Corresponds to [CLLocationCoordinate2D](https://developer.apple.com/documentation/corelocation/cllocationcoordinate2d) * and [LatLng](https://developers.google.com/android/reference/com/google/android/gms/maps/model/LatLng). */ @@ -25,7 +25,7 @@ declare module "react-native-google-places-api" { /** * Current place, with additional likelihood property. - * + * * Corresponds roughly to * [GMSPlaceLikelihood](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place_likelihood.html#a370caf145921ced6374bd39212561d90) * and [com.google.android.libraries.places.api.net.PlaceLikelihood](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/PlaceLikelihood), @@ -35,7 +35,7 @@ declare module "react-native-google-places-api" { /** * Returns a value from 0.0 to 1.0 indicating the confidence that the user * is at this place. - * + * * The larger the value the more confident we are of the place returned. For * example, a likelihood of 0.75 means that the user is at least 75% likely * to be at this place. @@ -50,9 +50,9 @@ declare module "react-native-google-places-api" { /** * Internal mapping to [GMSPlace](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place) * and [com.google.android.libraries.places.api.model.Place](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place). - * + * * Represents a particular physical space. - * + * * A Place encapsulates information about a physical location, including * its name, address, and any other information we might have about it. */ @@ -64,7 +64,7 @@ declare module "react-native-google-places-api" { /** * Place ID of this place. - * + * * For more information: [Place IDs](https://developers.google.com/places/place-id) */ placeID: string; @@ -76,7 +76,7 @@ declare module "react-native-google-places-api" { /** * Location of the place. - * + * * Corresponds to [coordinates](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place.html#a3dc43865df0de69b6b1203a15a745efc) * and [getLatLng](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place.html#getLatLng()). */ @@ -84,7 +84,7 @@ declare module "react-native-google-places-api" { /** * The Opening Hours information for this place. - * + * * The mapping only contains the weekday text, i.e. * [GMSOpeningHours#weekdayTest](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_opening_hours.html#a6a4cd04495230795fcd04d814c71d107) * and [OpeningHours#getWeekdayTest](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/OpeningHours.html#getWeekdayText()). @@ -100,7 +100,7 @@ declare module "react-native-google-places-api" { /** * Simple address of the Place. - * + * * Corresponds to [formattedAddress](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place.html#a8926a762ae78bcd18c0ea126d270ef3d) * and [getAddress](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place.html#getAddress()) */ @@ -108,37 +108,37 @@ declare module "react-native-google-places-api" { /** * Five-star rating for this place based on user reviews. - * + * * Ratings range from 1.0 to 5.0. 0.0 means we have no rating for this * place (e.g. because not enough users have reviewed this place). */ rating: number; /** - * Represents how many reviews make up this place's rating. + * Represents how many reviews make up this place's rating. */ userRatingsTotal: number; /** * Price level for this place, as integers from 0 to 4. - * + * * e.g. A value of 4 means this place is "$$$$" (expensive). A value of 0 * means free (such as a museum with free admission). */ priceLevel: any; /** - * The types of this place. + * The types of this place. */ types: ReturnPlaceType[]; /** * Website for this place. - * + * * This is the URI of the website maintained by the Place, if available. * This link is always for a third-party website not affiliated with the * Places API. - * + * * Corresponds to [website](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place.html#a7b9ee24d284ac279eed7f83a838354fe) * and [getWebsiteUri](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/Place.html#getWebsiteUri()). */ @@ -148,7 +148,7 @@ declare module "react-native-google-places-api" { * This returns a viewport of a size that is suitable for displaying this * place. For example, a Place object representing a store may have a * relatively small viewport, while a Place object representing a country - * may have a very large viewport. + * may have a very large viewport. */ viewport: GeoCoordinateBounds; @@ -162,13 +162,13 @@ declare module "react-native-google-places-api" { /** * Internal mapping to [GMSPlusCode](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_place) * and [com.google.android.libraries.places.api.model.PlusCode](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/PlusCode). - * + * * A class containing the Plus codes representation for a location. - * + * * Plus Code, or Open Location Code (OLC), is a geocode system for * identifying any geographical area on Earth, even when a street address - * does not exist. - * + * does not exist. + * * See https://plus.codes/ for more details. */ export interface PlusCode { @@ -188,7 +188,7 @@ declare module "react-native-google-places-api" { /** * Place Type, corresponding to the * [return types table 1](https://developers.google.com/places/ios-sdk/supported_types). - * + * * You can use the following values in the `types` filter for place * [searches](https://developers.google.com/places/web-service/search) * (Places API only). These types may also be returned anywhere a Place @@ -196,7 +196,8 @@ declare module "react-native-google-places-api" { * [Place Details](https://developers.google.com/places/android-sdk/place-details) * resulting from a call to `fetchPlace()`). */ - export type PlaceType = "accounting" + export type PlaceType = + | "accounting" | "airport" | "amusement_park" | "aquarium" @@ -285,24 +286,25 @@ declare module "react-native-google-places-api" { | "transit_station" | "travel_agency" | "veterinary_care" - | "zoo"; + | "zoo"; /** * Place Type, corresponding to the * [return types table 2](https://developers.google.com/places/ios-sdk/supported_types). - * + * * The following types may be returned anywhere a Place result is returned * (for example a [Find Place](https://developers.google.com/places/web-service/search#FindPlaceRequests) * request), in addition to the types in table 1 above. These types are also * used for address components. - * + * * For more details on these types, refer to * [Address Types](https://developers.google.com/maps/documentation/geocoding/intro#Types). - * + * * Note: The types below are not supported in the type filter of a place * search. */ - export type ReadOnlyPlaceType = "administrative_area_level_1" + export type ReadOnlyPlaceType = + | "administrative_area_level_1" | "administrative_area_level_2" | "administrative_area_level_3" | "administrative_area_level_4" @@ -349,7 +351,7 @@ declare module "react-native-google-places-api" { /** * Place Type, corresponding to the * [return types table 3](https://developers.google.com/places/ios-sdk/supported_types). - * + * * You may restrict results from a Place Autocomplete request to be of a * certain type by passing a `types` parameter. The parameter specifies a * type or a type collection, as listed in the supported types below. If @@ -357,50 +359,54 @@ declare module "react-native-google-places-api" { * type is allowed. The exception is that you can safely mix the `geocode` * and `establishment` types, but note that this will have the same effect * as specifying no types. - * + * * ## `geocode` - * + * * Instructs the Place Autocomplete service to return only geocoding * results, rather than business results. Generally, you use this request * to disambiguate results where the location specified may be * indeterminate. - * + * * ## `address` - * + * * Instructs the Place Autocomplete service to return only geocoding * results with a precise address. Generally, you use this request when * you know the user will be looking for a fully specified address. - * + * * ## `establishment` - * + * * Instructs the Place Autocomplete service to return only business * results. - * + * * ## `regions` - * + * * Instructs the Places service to return any result matching the * following types: - * + * * - `locality` (PlaceType.Locality) * - `sublocality` (PlaceType.SubLocality) * - `postal_code` (PlaceType.PostalCode) * - `country` (PlaceType.Country) * - `administrative_area_level_1` (PlaceType.AdministrativeAreaLevel1) * - `administrative_area_level_2` (PlaceType.AdministrativeAreaLevel2) - * + * * ## `cities` - * + * * Instructs the Places service to return results that match `locality` * (PlaceType.Locality) or `administrative_area_level_3` * (PlaceType.AdministrativeAreaLevel3). */ - export type AutocompleteType = "geocode" | "address" | "establishment" - | "regions" | "cities"; + export type AutocompleteType = + | "geocode" + | "address" + | "establishment" + | "regions" + | "cities"; /** * Internal mapping to [AddressComponent](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_address_component) * and [com.google.android.libraries.places.api.model.AddressComponent](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/AddressComponent). - * + * * Represents a component of an address, e.g., street number, postcode, * city, etc. */ @@ -411,7 +417,7 @@ declare module "react-native-google-places-api" { types: ReturnPlaceType[]; /** - * Name of the address component, e.g. "Sydney". + * Name of the address component, e.g. "Sydney". */ name: string; @@ -424,10 +430,10 @@ declare module "react-native-google-places-api" { /** * Internal mapping to [GMSAutocompletePrediction](https://developers.google.com/places/ios-sdk/reference/https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_autocomplete_prediction) * and [com.google.android.libraries.places.api.model.AutocompletePrediction](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/api/model/AutocompletePrediction). - * + * * Represents an autocomplete suggestion of a place, based on a particular * text query. - * + * * An AutocompletePrediction includes the description of the suggested place * as well as basic details including place ID and types. */ @@ -435,16 +441,16 @@ declare module "react-native-google-places-api" { /** * The full text of a place. This is a combination of the primary text * and the secondary text. - * - * Example: "Eiffel Tower, Avenue Anatole France, Paris, France" + * + * Example: "Eiffel Tower, Avenue Anatole France, Paris, France" */ fullText: string; /** * Returns the primary text of a place. This will usually be the name of * the place. - * - * Example: "Eiffel Tower", "123 Pitt Street" + * + * Example: "Eiffel Tower", "123 Pitt Street" */ primaryText: string; @@ -452,21 +458,21 @@ declare module "react-native-google-places-api" { * Returns the secondary text of a place. This provides extra context on * the place, and can be used as a second line when showing autocomplete * predictions. - * + * * Example: "Avenue Anatole France, Paris, France", "Sydney, New South - * Wales" + * Wales" */ secondaryText: string; /** * Returns the place ID of the place being referred to by this prediction. - * + * * For more information: [Place IDs](https://developers.google.com/places/place-id) */ placeID: string; /** - * The types of this autocomplete result. + * The types of this autocomplete result. */ types?: ReturnPlaceType; } @@ -474,7 +480,7 @@ declare module "react-native-google-places-api" { /** * Google Places options. - * + * * This type roughly corresponds to * [GMSAutocompleteFilter](https://developers.google.com/places/ios-sdk/reference/interface_g_m_s_autocomplete_filter) * and [com.google.android.libraries.places.widget.Autocomplete](https://developers.google.com/places/android-sdk/reference/com/google/android/libraries/places/widget/Autocomplete). @@ -496,7 +502,7 @@ declare module "react-native-google-places-api" { /** * If true, the autocomplete modal will * [open as an overlay rather than fullscreen](https://developers.google.com/places/images/acw_overlay.png). - * + * * Note: This property is Android only. */ useOverlay: boolean; @@ -504,7 +510,7 @@ declare module "react-native-google-places-api" { /** * If present, the autocomplete modal would launch with results * pre-populated for the query passed. - * + * * Note: This property is Android only. */ initialQuery: string; @@ -512,7 +518,7 @@ declare module "react-native-google-places-api" { /** * To bias autocomplete results to a specific geographic region. - * + * * Note: On iOS, only one of locationBias or locationRestriction is * respected, when passing both, only the first passed option would be used. */ @@ -520,7 +526,7 @@ declare module "react-native-google-places-api" { /** * To restrict autocomplete results to a specific geographic region. - * + * * Note: On iOS, only one of locationBias or locationRestriction is * respected, when passing both, only the first passed option would be used. */ @@ -529,43 +535,44 @@ declare module "react-native-google-places-api" { class RNGooglePlacesNative { public openAutocompleteModal( - autocompleteFilter: RNGooglePlacesNativeOptions, placeFields: K[], - ): Promise>>; + autocompleteFilter: RNGooglePlacesNativeOptions, + placeFields: K[] + ): Promise>>; public getAutocompletePredictions( - query: string, filterOptions: RNGooglePlacesNativeOptions, + query: string, + filterOptions: RNGooglePlacesNativeOptions ): Promise; public lookUpPlaceByID( - placeID: string, placeFields: K[] - ): Promise>; + placeID: string, + placeFields: K[] + ): Promise>; public getCurrentPlace( placeFields: K[] - ): Promise< - Pick[] - >; + ): Promise[]>; } class RNGooglePlaces { static optionsDefaults: { - type: '', - country: '', - useOverlay: false, - initialQuery: '', - useSessionToken: true, + type: ""; + country: ""; + useOverlay: false; + initialQuery: ""; + useSessionToken: true; locationBias: { - latitudeSW: 0, - longitudeSW: 0, - latitudeNE: 0, - longitudeNE: 0, - }, + latitudeSW: 0; + longitudeSW: 0; + latitudeNE: 0; + longitudeNE: 0; + }; locationRestriction: { - latitudeSW: 0, - longitudeSW: 0, - latitudeNE: 0, - longitudeNE: 0, - } + latitudeSW: 0; + longitudeSW: 0; + latitudeNE: 0; + longitudeNE: 0; + }; }; static placeFieldsDefaults: (keyof GMSTypes.Place)[]; @@ -575,12 +582,13 @@ declare module "react-native-google-places-api" { * select the result fields you need in your application. */ public openAutocompleteModal( - options?: Partial, + options?: Partial ): Promise; public openAutocompleteModal( - options: Partial, placeFields: K[], - ): Promise>; + options: Partial, + placeFields: K[] + ): Promise>; /** * If you have specific branding needs or you would rather build out your @@ -588,7 +596,8 @@ declare module "react-native-google-places-api" { * call these methods to call the native SDKs directly. */ public getAutocompletePredictions( - query: string, options?: Partial, + query: string, + options?: Partial ): Promise; /** @@ -597,25 +606,26 @@ declare module "react-native-google-places-api" { public lookUpPlaceByID(placeID: string): Promise; /** - * For more information: [Place IDs](https://developers.google.com/places/place-id) + * For more information: [Place IDs](https://developers.google.com/places/place-id) */ public lookUpPlaceByID( - placeID: string, placeFields: K[] - ): Promise>; + placeID: string, + placeFields: K[] + ): Promise>; /** * 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. Ensure you have required * the appropriate permissions as stated post-install steps above before * making this request. - * + * * The sum of the likelihoods in a given result set is always less than or - * equal to 1.0. - * + * equal to 1.0. + * * Note: To prevent yourself from incurring huge usage bill, you should * select only the result fields you need in your application. */ @@ -624,21 +634,19 @@ declare module "react-native-google-places-api" { /** * 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. Ensure you have required * the appropriate permissions as stated post-install steps above before * making this request. - * + * * The sum of the likelihoods in a given result set is always less than or - * equal to 1.0. + * equal to 1.0. */ public getCurrentPlace( placeFields: K[] - ): Promise< - Pick[] - >; + ): Promise[]>; } const _: RNGooglePlaces; diff --git a/react-native-google-places.podspec b/react-native-google-places.podspec index 376380d..478ac41 100644 --- a/react-native-google-places.podspec +++ b/react-native-google-places.podspec @@ -8,8 +8,8 @@ Pod::Spec.new do |s| s.description = package['description'] s.license = package['license'] s.author = package['author'] - s.homepage = 'https://github.com/marqroldan/react-native-google-places-api' - s.source = { :git => 'https://github.com/marqroldan/react-native-google-places-api.git', :tag => s.version } + s.homepage = 'https://github.com/marqroldan/react-native-google-places-native' + s.source = { :git => 'https://github.com/marqroldan/react-native-google-places-native.git', :tag => s.version } s.platform = :ios, '11.0' From bdc8ee45898e174df47c9fa1ff76f9ee58c8c7d7 Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Thu, 12 May 2022 07:59:08 +0800 Subject: [PATCH 18/26] #1 Updated SDK dependency version, increased min ios to 12.0 --- react-native-google-places.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/react-native-google-places.podspec b/react-native-google-places.podspec index 478ac41..4ee5415 100644 --- a/react-native-google-places.podspec +++ b/react-native-google-places.podspec @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.homepage = 'https://github.com/marqroldan/react-native-google-places-native' s.source = { :git => 'https://github.com/marqroldan/react-native-google-places-native.git', :tag => s.version } - s.platform = :ios, '11.0' + s.platform = :ios, '12.0' s.preserve_paths = 'README.md', 'package.json', 'index.js' s.source_files = 'ios/*.{h,m}' @@ -19,6 +19,6 @@ Pod::Spec.new do |s| s.compiler_flags = '-DHAVE_GOOGLE_MAPS=1', '-fno-modules' s.dependency 'React' - s.dependency 'GooglePlaces', '~> 5.1.0' - s.dependency 'GoogleMaps', '~> 5.1.0' + s.dependency 'GooglePlaces', '~> 6.1.0' + s.dependency 'GoogleMaps', '~> 6.1.0' end \ No newline at end of file From 4fdf63ac8a63c60e0c1bc5d99f8392d46acaf3b3 Mon Sep 17 00:00:00 2001 From: Marq Roldan Date: Thu, 12 May 2022 08:01:04 +0800 Subject: [PATCH 19/26] #1 Updated version to 1.1.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bb68e4e..326e591 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", "author": "Marq Roldan ", - "version": "1.0.0", + "version": "1.1.0", "scripts": {}, "repository": { "type": "git", From 95f710fc73ff10e68fce9df259ca82a2f310e89e Mon Sep 17 00:00:00 2001 From: Matheus Felisberto Date: Thu, 20 Aug 2020 13:45:45 -0300 Subject: [PATCH 20/26] update(podspec): google sdks dependencies --- react-native-google-places.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react-native-google-places.podspec b/react-native-google-places.podspec index 4ee5415..1bdc14f 100644 --- a/react-native-google-places.podspec +++ b/react-native-google-places.podspec @@ -21,4 +21,4 @@ Pod::Spec.new do |s| s.dependency 'React' s.dependency 'GooglePlaces', '~> 6.1.0' s.dependency 'GoogleMaps', '~> 6.1.0' -end \ No newline at end of file +end From 52124ccf2da1befc3c633dead94fe43f591dadb8 Mon Sep 17 00:00:00 2001 From: Felipe Amaral Date: Mon, 15 Feb 2021 17:03:59 -0300 Subject: [PATCH 21/26] chore(session): add begin autocomplete session to android --- .../rngoogleplaces/RNGooglePlacesModule.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java b/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java index b65868f..b6198bd 100644 --- a/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java +++ b/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java @@ -69,6 +69,7 @@ public class RNGooglePlacesModule extends ReactContextBaseJavaModule implements private List lastSelectedFields; public static final String TAG = "RNGooglePlaces"; private PlacesClient placesClient; + private AutocompleteSessionToken sessionToken; public static int AUTOCOMPLETE_REQUEST_CODE = 360; public static String REACT_CLASS = "RNGooglePlaces"; @@ -121,6 +122,16 @@ public void onActivityResult(Activity activity, final int requestCode, final int * Exposed React's methods */ + @ReactMethod + public void beginAutocompleteSession() { + sessionToken = AutocompleteSessionToken.newInstance(); + } + + @ReactMethod + public void cancelAutocompleteSession() { + sessionToken = null; + } + @ReactMethod public void openAutocompleteModal(ReadableMap options, ReadableArray fields, final Promise promise) { @@ -233,8 +244,8 @@ public void getAutocompletePredictions(String query, ReadableMap options, final requestBuilder.setTypeFilter(getFilterType(type)); - if (useSessionToken) { - requestBuilder.setSessionToken(AutocompleteSessionToken.newInstance()); + if (sessionToken != null) { + requestBuilder.setSessionToken(sessionToken); } Task task = From b12e05acc0abc257209b4671a191e5f0d01dec5c Mon Sep 17 00:00:00 2001 From: Felipe Amaral Date: Mon, 15 Feb 2021 17:04:09 -0300 Subject: [PATCH 22/26] chore(session): add begin autocomplete session to ios --- ios/RNGooglePlaces.m | 48 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/ios/RNGooglePlaces.m b/ios/RNGooglePlaces.m index c873b18..f8feb9b 100644 --- a/ios/RNGooglePlaces.m +++ b/ios/RNGooglePlaces.m @@ -13,6 +13,7 @@ @interface RNGooglePlaces() @property (strong, nonatomic) CLLocationManager *locationManager; +@property GMSAutocompleteSessionToken *sessionToken; @end @@ -49,6 +50,46 @@ - (void)dealloc self.locationManager = nil; } +RCT_EXTERN_METHOD(beginAutocompleteSession); +- (void)beginAutocompleteSession +{ + self.sessionToken = [GMSAutocompleteSessionToken new]; +} + +RCT_EXTERN_METHOD(cancelAutocompleteSession); +- (void)cancelAutocompleteSession +{ + self.sessionToken = nil; +} + +RCT_EXPORT_METHOD(openAutocompleteModal: (NSDictionary *)options + withFields: (NSArray *)fields + resolver: (RCTPromiseResolveBlock)resolve + rejecter: (RCTPromiseRejectBlock)reject) +{ + + @try { + RNGooglePlacesViewController* acController = [[RNGooglePlacesViewController alloc] init]; + + GMSPlaceField selectedFields = [self getSelectedFields:fields isCurrentOrFetchPlace:false]; + + GMSAutocompleteFilter *autocompleteFilter = [[GMSAutocompleteFilter alloc] init]; + autocompleteFilter.type = [self getFilterType:[RCTConvert NSString:options[@"type"]]]; + autocompleteFilter.country = [options[@"country"] length] == 0? nil : options[@"country"]; + + NSDictionary *locationBias = [RCTConvert NSDictionary:options[@"locationBias"]]; + NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]]; + + + GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; + + [acController openAutocompleteModal: autocompleteFilter placeFields: selectedFields bounds: autocompleteBounds boundsMode: self.boundsMode resolver: resolve rejecter: reject]; + } + @catch (NSException * e) { + reject(@"E_OPEN_FAILED", @"Could not open modal", [self errorFromException:e]); + } +} + RCT_EXPORT_METHOD(getAutocompletePredictions: (NSString *)query filterOptions: (NSDictionary *)options resolver: (RCTPromiseResolveBlock)resolve @@ -64,11 +105,12 @@ - (void)dealloc [self getBounds:locationBias andRestrictOptions:locationRestriction filter:autocompleteFilter]; - GMSAutocompleteSessionToken *token = [[GMSAutocompleteSessionToken alloc] init]; - + + GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; + [[GMSPlacesClient sharedClient] findAutocompletePredictionsFromQuery:query filter:autocompleteFilter - sessionToken:token + sessionToken:self.sessionToken callback:^(NSArray * _Nullable results, NSError *error) { if (error != nil) { reject(@"E_AUTOCOMPLETE_ERROR", [error description], nil); From 6489991c89e62734d94f342bd930ef90cc2925d8 Mon Sep 17 00:00:00 2001 From: Felipe Amaral Date: Mon, 15 Feb 2021 17:04:20 -0300 Subject: [PATCH 23/26] chore(session): add begin autocomplete session to index --- index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/index.js b/index.js index 0190504..a17e382 100644 --- a/index.js +++ b/index.js @@ -49,6 +49,14 @@ class RNGooglePlaces { getCurrentPlace(placeFields = []) { return RNGooglePlacesNative.getCurrentPlace([...RNGooglePlaces.placeFieldsDefaults, ...placeFields]) } + + beginAutocompleteSession() { + return RNGooglePlacesNative.beginAutocompleteSession(); + } + + cancelAutocompleteSession() { + return RNGooglePlacesNative.cancelAutocompleteSession(); + } } export default new RNGooglePlaces() \ No newline at end of file From e82b7a206157b287b42fd4d595321a31935ba359 Mon Sep 17 00:00:00 2001 From: Eduardo Freitas Date: Mon, 12 Dec 2022 13:44:36 +0000 Subject: [PATCH 24/26] fix: add missing session token into lookUpPlaceByID method --- .../reactnative/rngoogleplaces/RNGooglePlacesModule.java | 8 +++++++- ios/RNGooglePlaces.m | 2 +- package.json | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java b/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java index b6198bd..f3ae9f9 100644 --- a/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java +++ b/android/src/main/java/com/arttitude360/reactnative/rngoogleplaces/RNGooglePlacesModule.java @@ -300,7 +300,13 @@ public void lookUpPlaceByID(String placeID, ReadableArray fields, final Promise List selectedFields = getPlaceFields(fields.toArrayList(), false); - FetchPlaceRequest request = FetchPlaceRequest.builder(placeID, selectedFields).build(); + FetchPlaceRequest.Builder requestBuilder = FetchPlaceRequest.builder(placeID, selectedFields); + + if (sessionToken != null) { + requestBuilder.setSessionToken(sessionToken); + } + + FetchPlaceRequest request = requestBuilder.build(); placesClient.fetchPlace(request).addOnSuccessListener((response) -> { Place place = response.getPlace(); diff --git a/ios/RNGooglePlaces.m b/ios/RNGooglePlaces.m index f8feb9b..1d37290 100644 --- a/ios/RNGooglePlaces.m +++ b/ios/RNGooglePlaces.m @@ -144,7 +144,7 @@ - (void)cancelAutocompleteSession { GMSPlaceField selectedFields = [self getSelectedFields:fields isCurrentOrFetchPlace:false]; - [[GMSPlacesClient sharedClient] fetchPlaceFromPlaceID:placeID placeFields:selectedFields sessionToken:nil + [[GMSPlacesClient sharedClient] fetchPlaceFromPlaceID:placeID placeFields:selectedFields sessionToken:self.sessionToken callback:^(GMSPlace * _Nullable place, NSError * _Nullable error) { if (error != nil) { reject(@"E_PLACE_DETAILS_ERROR", [error localizedDescription], nil); diff --git a/package.json b/package.json index 326e591..b3a4345 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,8 @@ "name": "react-native-google-places-native", "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", - "author": "Marq Roldan ", - "version": "1.1.0", + "author": "Tolu Olowu (Arttitude 360) ", + "version": "3.1.5", "scripts": {}, "repository": { "type": "git", From 2aeeeeed6707de3286d25a481464155b5aa84000 Mon Sep 17 00:00:00 2001 From: Eduardo Freitas Date: Tue, 7 Mar 2023 15:06:55 +0000 Subject: [PATCH 25/26] feat: update places sdk with rebase and update/fix break changes --- .gitignore | 2 +- ios/RNGooglePlaces.h | 3 ++- ios/RNGooglePlaces.m | 10 ++++------ ios/RNGooglePlacesViewController.h | 7 ++++++- ios/RNGooglePlacesViewController.m | 18 ++++++++++++++++++ package.json | 18 +++++++++--------- react-native-google-places.podspec | 4 ++-- 7 files changed, 42 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 8bb8459..50c7247 100644 --- a/.gitignore +++ b/.gitignore @@ -55,7 +55,7 @@ project.xcworkspace # Android/IJ # -react-native-google-places-native.iml +react-native-google-places.iml .idea .gradle .vscode diff --git a/ios/RNGooglePlaces.h b/ios/RNGooglePlaces.h index c5fe3c6..8db30b9 100644 --- a/ios/RNGooglePlaces.h +++ b/ios/RNGooglePlaces.h @@ -4,12 +4,13 @@ #import #import +#import #import @interface RNGooglePlaces : NSObject - (GMSPlacesAutocompleteTypeFilter) getFilterType:(NSString *)type; - (GMSPlaceField) getSelectedFields:(NSArray *)fields isCurrentOrFetchPlace:(Boolean)currentOrFetch; -- (void) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions filter: (GMSAutocompleteFilter *)autocompleteFilter; +- (GMSCoordinateBounds *) getBounds: (NSDictionary *)biasOptions andRestrictOptions: (NSDictionary *)restrictOptions filter: (GMSAutocompleteFilter *)autocompleteFilter; @end diff --git a/ios/RNGooglePlaces.m b/ios/RNGooglePlaces.m index 1d37290..5db0266 100644 --- a/ios/RNGooglePlaces.m +++ b/ios/RNGooglePlaces.m @@ -8,6 +8,7 @@ #import #import +#import #import @interface RNGooglePlaces() @@ -81,9 +82,9 @@ - (void)cancelAutocompleteSession NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]]; - GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; + GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction filter:autocompleteFilter]; - [acController openAutocompleteModal: autocompleteFilter placeFields: selectedFields bounds: autocompleteBounds boundsMode: self.boundsMode resolver: resolve rejecter: reject]; + [acController openAutocompleteModal: autocompleteFilter placeFields: selectedFields bounds: autocompleteBounds resolver: resolve rejecter: reject]; } @catch (NSException * e) { reject(@"E_OPEN_FAILED", @"Could not open modal", [self errorFromException:e]); @@ -103,10 +104,7 @@ - (void)cancelAutocompleteSession NSDictionary *locationBias = [RCTConvert NSDictionary:options[@"locationBias"]]; NSDictionary *locationRestriction = [RCTConvert NSDictionary:options[@"locationRestriction"]]; - [self getBounds:locationBias andRestrictOptions:locationRestriction filter:autocompleteFilter]; - - - GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction]; + GMSCoordinateBounds *autocompleteBounds = [self getBounds:locationBias andRestrictOptions:locationRestriction filter:autocompleteFilter]; [[GMSPlacesClient sharedClient] findAutocompletePredictionsFromQuery:query filter:autocompleteFilter diff --git a/ios/RNGooglePlacesViewController.h b/ios/RNGooglePlacesViewController.h index ff19032..3fc6c35 100644 --- a/ios/RNGooglePlacesViewController.h +++ b/ios/RNGooglePlacesViewController.h @@ -1,4 +1,5 @@ #import +#import #import #import @@ -8,5 +9,9 @@ @property(nonatomic, strong) RNGooglePlacesViewController *instance; - (instancetype) init; - +- (void)openAutocompleteModal: (GMSAutocompleteFilter *)autocompleteFilter + placeFields: (GMSPlaceField)selectedFields + bounds: (GMSCoordinateBounds *)autocompleteBounds + resolver: (RCTPromiseResolveBlock)resolve + rejecter: (RCTPromiseRejectBlock)reject; @end diff --git a/ios/RNGooglePlacesViewController.m b/ios/RNGooglePlacesViewController.m index 28dd6bd..a2f7d5e 100644 --- a/ios/RNGooglePlacesViewController.m +++ b/ios/RNGooglePlacesViewController.m @@ -1,6 +1,7 @@ #import "RNGooglePlacesViewController.h" #import "NSMutableDictionary+GMSPlace.h" +#import #import #import #import @@ -24,6 +25,23 @@ - (instancetype)init return self; } +- (void)openAutocompleteModal: (GMSAutocompleteFilter *)autocompleteFilter + placeFields: (GMSPlaceField)selectedFields + bounds: (GMSCoordinateBounds *)autocompleteBounds + resolver: (RCTPromiseResolveBlock)resolve + rejecter: (RCTPromiseRejectBlock)reject; +{ + _resolve = resolve; + _reject = reject; + + GMSAutocompleteViewController *viewController = [[GMSAutocompleteViewController alloc] init]; + viewController.autocompleteFilter = autocompleteFilter; + viewController.placeFields = selectedFields; + viewController.delegate = self; + UIViewController *topController = [self getTopController]; + [topController presentViewController:viewController animated:YES completion:nil]; +} + // Handle the user's selection. - (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithPlace:(GMSPlace *)place diff --git a/package.json b/package.json index b3a4345..ef0ce78 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,20 @@ { - "name": "react-native-google-places-native", + "name": "react-native-google-places", "description": "iOS/Android Google Places Widgets (Autocomplete Modals) and API Services for React Native Apps", "main": "index.js", - "author": "Tolu Olowu (Arttitude 360) ", - "version": "3.1.5", + "authors": "Tolu Olowu (Arttitude 360) , Amenulhaq ", + "version": "3.1.6", "scripts": {}, "repository": { "type": "git", - "url": "git+https://github.com/marqroldan/react-native-google-places-native.git" + "url": "https://github.com/gympass/react-native-google-places" }, "license": "MIT", "bugs": { - "url": "https://github.com/marqroldan/react-native-google-places-native/issues" + "url": "https://github.com/gympass/react-native-google-places/issues" }, "types": "index.d.ts", - "homepage": "https://github.com/marqroldan/react-native-google-places-native/blob/master/README.md", + "homepage": "https://github.com/gympass/react-native-google-places#readme", "keywords": [ "react", "react-native", @@ -23,9 +23,9 @@ "places", "google-places", "Google Places API", - "Google places darkmode", - "Google darkmode", - "darkmode autocomplete", + "Google places darkmode", + "Google darkmode", + "darkmode autocomplete", "autocomplete", "ios", "android" diff --git a/react-native-google-places.podspec b/react-native-google-places.podspec index 1bdc14f..bc7d352 100644 --- a/react-native-google-places.podspec +++ b/react-native-google-places.podspec @@ -8,8 +8,8 @@ Pod::Spec.new do |s| s.description = package['description'] s.license = package['license'] s.author = package['author'] - s.homepage = 'https://github.com/marqroldan/react-native-google-places-native' - s.source = { :git => 'https://github.com/marqroldan/react-native-google-places-native.git', :tag => s.version } + s.homepage = 'https://github.com/tolu360/react-native-google-places' + s.source = { :git => 'https://github.com/tolu360/react-native-google-places.git', :tag => s.version } s.platform = :ios, '12.0' From afdf8f4c1e61e05909a3338ca1c55b07756235f4 Mon Sep 17 00:00:00 2001 From: Eduardo Freitas Date: Tue, 7 Mar 2023 16:21:56 +0000 Subject: [PATCH 26/26] fix: bumd to right version --- react-native-google-places.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/react-native-google-places.podspec b/react-native-google-places.podspec index e18680a..eab7cca 100644 --- a/react-native-google-places.podspec +++ b/react-native-google-places.podspec @@ -19,6 +19,6 @@ Pod::Spec.new do |s| s.compiler_flags = '-DHAVE_GOOGLE_MAPS=1', '-fno-modules' s.dependency 'React' - s.dependency 'GooglePlaces', '~> 6.1.0' - s.dependency 'GoogleMaps', '~> 6.1.0' + s.dependency 'GooglePlaces', '~> 6.1.1' + s.dependency 'GoogleMaps', '~> 6.1.1' end