Page Summary
-
The Places SDK for iOS provides a demo app showcasing features like place autocomplete and place photos, with code snippets and a full sample app for exploration.
-
To run the sample app, download the archive, navigate to the GooglePlaces directory, install dependencies using CocoaPods, and open the Xcode workspace.
-
Before building, enable the Places SDK for iOS in your Google Cloud project, obtain an API key (restricting it to the app's bundle identifier for security), and add your API key to the
SDKDemoAPIKeyfile. -
Build and run the app, granting location access if prompted, to explore the available Places Demos and utilize the provided sample code as a starting point for your own applications.
The Places SDK for iOS demo app on GitHub supplied with the Places SDK for iOS demonstrate a number of features including Place Autocomplete and Place Photos. In addition, you can find code snippets on each page of this developer's guide. Import and build the app, add your API key, view the demo, and use the sample code supplied as a starting point for your app.
When you run the sample app, it displays a list of available samples that you can run on your own device. Select one of the options.
Run the full sample app locally
The Places SDK for iOS sample app is available as a download archive from GitHub Follow these steps to install and try the Places SDK for iOS sample app.
- Download
the code sample archive from
GitHub
and unpack the archive. Alternatively, clone the repository into a local directory:
git clone https://github.com/googlemaps-samples/ios-places-sdk-samples.git
Open a terminal window, navigate to the directory where you expanded the sample files, and drill down into the directory for the version you want to use:
SwiftUI
cd ios-places-sdk-samples/GooglePlacesDemos/
open GooglePlacesDemos.xcodeprojSwift
cd ios-places-sdk-samples/GooglePlaces-Swift/
open GooglePlacesSwiftDemos.xcodeprojObjective-C
cd ios-places-sdk-samples/Archive/GooglePlaces
open GooglePlacesXCFrameworkDemos.xcodeproj- In the Xcode project, go to File > Add Package Dependencies. Enter https://github.com/googlemaps/ios-places-sdk as the URL, press Enter to pull in the package, and click Add Package.
- Enable the Places SDK for iOS and the Maps SDK for iOS for your Google Cloud console project.
- Get an API key from your project with the Places API and/or Places API (New) enabled.
- Add your API key to the app using the appropriate instructions below.
SwiftUI
Create a local configuration file called
GooglePlacesDemos.xcconfigfor your API key, in the same directory as the demo application'sInfo.plistfile (GooglePlacesDemos/GooglePlacesDemos).Add two lines to your config file to define your API keys:
PLACES_API_KEY = YOUR_PLACES_API_KEYandMAPS_API_KEY = YOUR_MAPS_API_KEY.Substitute
YOUR_PLACES_API_KEYandYOUR_MAPS_API_KEYwith the API keys from the previous steps.See Configuration Settings File (xcconfig) format for help on creating a local configuration file.
Swift
Edit the
SDKDemoAPIKeyfile and paste your API key into the appropriate constant. For example:let placesAPIKey = "YOUR_API_KEY"
If present, remove the following line:
#error (Register for API Key and insert here. Then delete this line.)
If Xcode prompts you to unlock the
SDKDemoAPIKeyfile for editing, choose Unlock.Objective-C
Edit the
SDKDemoAPIKeyfile and paste your API key into the appropriate constant. For example:static NSString *const kAPIKey = @"YOUR_API_KEY";
If present, remove the following line
#error (Register for API Key and insert here. Then delete this line.)If Xcode prompts you to unlock the
SDKDemoAPIKeyfile for editing, choose Unlock. - Build the app.
- If the build fails or the app crashes with an error about your API key when you first run it, make sure that you have provided the keys required in the instructions above.
- If you run the sample app, the iOS simulator window will show a list of Places Demos.
- If prompted to allow the demo app to access your location, choose Allow.
- The sample you chose is now ready to run.