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.
Open a terminal window, navigate to the directory where you expanded the sample files, and drill down into the GooglePlaces directory:
Swift
cd maps-sdk-for-ios-samples-master/GooglePlaces-Swift
pod install
open GooglePlacesDemos.xcworkspace
Objective-C
cd maps-sdk-for-ios-samples-master/GooglePlaces
pod install
open GooglePlacesDemos.xcworkspace
- Enable the Places SDK for iOS for your Google Cloud console project.
- If you don't yet have an API key, follow the
instructions to set up
a project on the Cloud console and get an API key. When configuring the
key on the Cloud console, you can
restrict the key to the
sample app's bundle identifier to ensure that only your app can use the key. The default bundle
identifier of the SDK samples app is
com.example.GooglePlacesDemos
. - Edit the
SDKDemoAPIKey
file and paste your API key into the appropriate constant. For example:Swift
let placesAPIKey = "YOUR_API_KEY"
Objective-C
static NSString *const kAPIKey = @"YOUR_API_KEY";
- If Xcode prompts you to unlock the
SDKDemoAPIKey
file for editing, choose Unlock. - If present, remove the following line, because it's used to register the
issue:
Swift
#error (Register for API Key and insert here. Then delete this line.)
Objective-C
#error Register your API key and insert here, then delete this line.
- 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
SDKDemoAPIKey
file. - If you are running the GooglePlaces samples, 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.