The SDK demo apps supplied with the Google Places API for iOS demonstrate a number of features including the place picker, 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 Google Places API for iOS is available as a CocoaPods pod. CocoaPods is an open source dependency manager for Swift and Objective-C Cocoa projects.
The Google Places API for iOS supplies a set of SDK demo apps that you can
install and run using the
pod try command:
- GooglePlaces demonstrates place autocomplete and place photos.
- GooglePlacePicker demonstrates the place picker.
Follow these steps to install CocoaPods and try the Google Places API 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
- Open a terminal window and run one of the following commands:
pod try GooglePlaces
pod try GooglePlacePicker
CocoaPods updates your spec repositories, then opens the SDK demos in a temporary Xcode project, either
GooglePlacePickerDemos.xcworkspace, depending on which demo you have chosen.
- Enable both the Google Places API for iOS and Google Maps SDK for iOS for your Google API Console project.
- If you don't yet have an API key, follow the
instructions to set up
a project on the Google API Console and get an API key. When configuring the
key on the Google API 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 either
com.example.GooglePlacePickerDemos, depending on which demo you have chosen.
- Edit the
SDKDemoAPIKeyfile and paste your API key into the appropriate constant. In the case of the place picker demo this is the
kMapsAPIKeyconstants. For example:
internal let kPlacesAPIKey = "YOUR_API_KEY" internal let kMapsAPIKey = "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 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, double check to 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 or GooglePlacePickerDemos 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 place picker, autocomplete, get current place, photos, and other pages in this guide.