The SDK demo apps 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.
Try the SDK demos using CocoaPods
The Places SDK for iOS is available as a CocoaPods pod. CocoaPods is an open source dependency manager for Swift and Objective-C Cocoa projects.
The Places SDK for iOS supplies a set of SDK demo apps that you can
install and run using the
pod try command:
Follow these steps to install CocoaPods and try the Places SDK for iOS:
- If you don't already have the CocoaPods tool, install it on macOS by
running the following command from the terminal. For details, see the CocoaPods
Getting Started guide.
sudo gem install cocoapods
- Get the sample files using one of these two methods:
Use files from GitHub
- Download the code sample archive from GitHub and unpack the archive.
- Open a terminal window, navigate to the directory where you expanded the sample files, and
drill down into the GooglePlaces directory:
- Run the following command:
Use CocoaPods v1.6.1
- Open a terminal window and install version 1.6.1:
sudo gem install cocoapods -v1.6.1
- Fetch the Google Places files using Cocoapods:
pod try GooglePlaces
CocoaPods updates your spec repositories, then opens the SDK demos in a temporary Xcode project,
- Enable the Places SDK for iOS for your Google Cloud Platform Console project.
- If you don't yet have an API key, follow the
instructions to set up
a project on the Google Cloud Platform Console and get an API key. When configuring the
key on the Google Cloud Platform Console, you can specify your app's bundle identifier to
ensure that only your app can use the key. The default bundle identifier of
the SDK samples app is
- Edit the
SDKDemoAPIKeyfile and paste your API key into the appropriate constant. For example:
let placesAPIKey = "YOUR_API_KEY"
static NSString *const kAPIKey = @"YOUR_API_KEY";
- If Xcode prompts you to unlock the
SDKDemoAPIKeyfile for editing, choose Unlock.
- If present, remove the following line, because it's used to register the
#error (Register for API Key and insert here. Then delete this line.”)
#error Register your API key and insert here, then delete this line.
- Build and run the project again.
- 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
- If you are running the GooglePlaces demos, the iOS simulator window will show a list of Places Demos.
- If prompted to allow GooglePlacesDemos to access your location, choose Allow.
- The sample you chose is now ready to run.
Use code snippets from the developer's guide
Each page in the developer's guide includes code snippets illustrating a particular feature of the API. For example, see the guides for autocomplete, get current place, photos, and other pages in this guide.