Follow the steps in this guide to download the Places SDK for iOS, to add the library and its dependencies to your app, and to get an API key at no charge.
Release notes are available for each release.
Step 1: Get the latest version of Xcode
To build a project using the Places SDK for iOS, you need:
Step 2: Install the SDK
To install the API in a new project, follow these steps:Use Cocoapods
The Places SDK for iOS is available as a CocoaPod pod, GooglePlaces, which contains all places functionality.
CocoaPods is an open source dependency manager for Swift and Objective-C Cocoa projects. 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
Create a Podfile
for the Places SDK for iOS and use
it to install the SDK and its dependencies:
- If you don't have an Xcode project yet, create one now and save it to your local machine. If you're newer to iOS development, create a new project and select the iOS App template.
- Create a file named
Podfile
in your project directory. This file defines your project's dependencies. - Edit the
Podfile
and add your dependencies along with their versions. Here is an example which specifies your application target name, and the name of theGooglePlaces
pod:source 'https://github.com/CocoaPods/Specs.git' platform :ios, '14.0' target 'YOUR_APPLICATION_TARGET_NAME_HERE' do pod 'GooglePlaces', '8.0.0' end
Make sure to regularly runpod outdated
to detect when there is a newer version to ensure you're always on the latest. - Save the
Podfile
. Open a terminal and go to the directory containing the
Podfile
:cd <path-to-project>
Run the
pod install
command. This will install the APIs specified in thePodfile
, along with any dependencies they may have.pod install
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.
To update the API for an existing project, follow these steps:
- Open a terminal and go to the project directory containing the
Podfile
. - Run the
pod update
command. This will update all of the APIs specified in thePodfile
to the latest version.
Use Carthage
The Places SDK for iOS is available to use with Carthage, a simple, decentralized dependency manager for Swift and Objective-C Cocoa projects.
- Install Carthage. There are several methods, so see the Carthage README file for exact steps.
- If you don't have an Xcode project yet, create one now and save it to your local machine. If you're newer to iOS development, create a new project and select the iOS App template.
- Create a file named
Cartfile
in your project directory. This file defines your project's dependencies. - Edit the
Cartfile
and add your dependencies along with their versions:
binary "https://dl.google.com/geosdk/GooglePlaces.json" == 6.2.1
Make sure to regularly runcarthage outdated
to detect when there is a newer version to ensure you're always on the latest. - Save the
Cartfile
. - In a terminal window, go to the directory containing the
Cartfile
:
cd <path-to-project>
- Run the
carthage update
command. This will install the APIs specified in theCartfile
, along with any dependencies they may have. - In the Finder, in your project directory, go to the downloaded framework files under
Carthage/Build/iOS
. - Drag the following bundles into your project (when prompted, select
Copy items if needed):
GooglePlaces-x.x.x/Frameworks/GooglePlaces.xcframework
- Right-click
GooglePlaces.xcframework
in your project, and select Show In Finder. - Drag the
GooglePlaces.bundle
from theResources
folder into your project. When prompted, ensure Copy items into destination group's folder is not selected. - Select your project from the Project Navigator, and choose your application's target.
- Open the Build Phases tab, and within Link Binary with
Libraries, add the following frameworks and libraries:
CoreGraphics.framework
CoreLocation.framework
libc++.tbd
libz.tbd
QuartzCore.framework
UIKit.framework
Choose your project, rather than a specific target, and open the Build Settings tab.
- In the Other Linker Flags section,
add
-ObjC
. If these settings are not visible, change the filter in the Build Settings bar from Basic to All.
To update the API for an existing project, follow these steps:
- Open a terminal and go to the project directory containing the
Cartfile
. - Run the
carthage update
command. This will update all of the APIs specified in theCartfile
to the latest version.
Install manually
This guide shows how to manually add the GooglePlaces framework to your project and configure your build settings in Xcode.
- Download the SDK source files: GooglePlaces-8.0.0
- Unpack the source files.
- Launch Xcode and either open an existing project, or create a new project. If you're newer to iOS development, create a new project and select the iOS App template.
- Remove any Maps bundles from previous releases from your project.
- Drag the following bundles into your project (when prompted, select
Copy items if needed):
GooglePlaces-x.x.x/Frameworks/GooglePlaces.xcframework
- Right-click
GooglePlaces.xcframework
in your project, and select Show In Finder. - Drag the
GooglePlaces.bundle
from theResources
folder into your project. When prompted, ensure Copy items into destination group's folder is not selected. - Select your project from the Project Navigator, and choose your application's target.
- Open the Build Phases tab, and within Link Binary with
Libraries, add the following frameworks and libraries:
CoreGraphics.framework
CoreLocation.framework
libc++.tbd
libz.tbd
QuartzCore.framework
UIKit.framework
Choose your project, rather than a specific target, and open the Build Settings tab.
- In the Other Linker Flags section,
add
-ObjC
. If these settings are not visible, change the filter in the Build Settings bar from Basic to All.
Install the XCFramework
An XCFramework is a binary package that you can use on multiple platforms, including machines using the M1 chipset, to install the Places SDK for iOS. This guide shows how to add the XCFramework containing the Places SDK for iOS to your project and configure your build settings in Xcode.
With Carthage
The Places SDK for iOS is available to use with Carthage, a simple, decentralized dependency manager for Swift and Objective-C Cocoa projects.
- Install Carthage. There are several methods, so see the Carthage README file for exact steps.
- If you don't have an Xcode project yet, create one now and save it to your local machine. If you're newer to iOS development, create a new project and select the iOS App template.
- Create a file named
Cartfile
in your project directory. This file defines your project's dependencies. Edit the
Cartfile
and add your dependencies along with their versions:binary "https://dl.google.com/geosdk/GooglePlaces.json" == 6.2.1-beta
- Save the
Cartfile
. In a terminal window, go to the directory containing the
Cartfile
:cd <path-to-project>
- Run the
carthage update
command. This will install the APIs specified in theCartfile
, along with any dependencies they may have. - In the Finder, in your project directory, go to the downloaded framework files
under
Carthage/Build
. - Drag the following XCFramework into your project under
Frameworks, Libraries, and Embedded Content. Make sure
to select Do Not Embed:
GooglePlaces-x.x.x/GooglePlaces.xcframework
- Right-click
GooglePlaces.xcframework
in your project, and select Show In Finder. - Drag the
GooglePlaces.bundle
from theios-arm64/GooglePlaces.framework/Resources
folder into the top level directory of your Xcode project. When prompted, ensure Copy items into destination group's folder is not selected. - Select your project from the Project Navigator, and choose your application's target.
- Open the Build Phases tab, and within Link Binary with
Libraries, and add the following frameworks and libraries:
CoreGraphics.framework
CoreLocation.framework
libc++.tbd
libz.tbd
QuartzCore.framework
UIKit.framework
Choose your project, rather than a specific target, and open the Build Settings tab.
- In the Other Linker Flags section,
add
-ObjC
. If these settings are not visible, change the filter in the Build Settings bar from Basic to All.
Manually
This guide shows how to manually add the Maps SDK for iOS to your project and configure your build settings in Xcode.
- Download the SDK source files: GooglePlaces-8.0.0.
- Unpack the source files. Navigate to the Frameworks folder to access the XCFramework.
- Launch Xcode and either open an existing project, or create a new project. If you're new to iOS, create a new project and select the iOS App template.
- Drag the following XCFramework into your project under
Frameworks, Libraries, and Embedded Content. Make sure
to select Do Not Embed:
GooglePlaces-x.x.x/GooglePlaces.xcframework
- Right-click
GooglePlaces.xcframework
in your project, and select Show In Finder. - Drag the
GooglePlaces.bundle
from theios-arm64/GooglePlaces.framework/Resources
folder into the top level directory of your Xcode project. When prompted, ensure Copy items into destination group's folder is not selected. - Select your project from the Project Navigator, and choose your application's target.
- Open the Build Phases tab, and within Link Binary with
Libraries, and add the following frameworks and libraries:
CoreGraphics.framework
CoreLocation.framework
libc++.tbd
libz.tbd
QuartzCore.framework
UIKit.framework
Choose your project, rather than a specific target, and open the Build Settings tab.
- In the Other Linker Flags section,
add
-ObjC
. If these settings are not visible, change the filter in the Build Settings bar from Basic to All.
Step 3: Add the API key to your app
In the following examples, replace YOUR_API_KEY
with your API key.
Swift
Add your API key to your AppDelegate.swift
as follows:
- Add the following import statement:
import GooglePlaces
- Add the following to your
application(_:didFinishLaunchingWithOptions:)
method, replacing YOUR_API_KEY with your API key:GMSPlacesClient.provideAPIKey("YOUR_API_KEY")
Objective-C
Add your API key to your AppDelegate.m
as follows:
- Add the following import statement:
@import GooglePlaces;
- Add the following to your
application:didFinishLaunchingWithOptions:
method, replacing YOUR_API_KEY with your API key:[GMSPlacesClient provideAPIKey:@"YOUR_API_KEY"];
Step 4: Start writing code
The following code samples demonstrate how to get the current place.
Swift
import GooglePlaces import UIKit class GetStartedViewController : UIViewController { // Add a pair of UILabels in Interface Builder, and connect the outlets to these variables. @IBOutlet private var nameLabel: UILabel! @IBOutlet private var addressLabel: UILabel! private var placesClient: GMSPlacesClient! override func viewDidLoad() { super.viewDidLoad() placesClient = GMSPlacesClient.shared() } // Add a UIButton in Interface Builder, and connect the action to this function. @IBAction func getCurrentPlace(_ sender: UIButton) { let placeFields: GMSPlaceField = [.name, .formattedAddress] placesClient.findPlaceLikelihoodsFromCurrentLocation(withPlaceFields: placeFields) { [weak self] (placeLikelihoods, error) in guard let strongSelf = self else { return } guard error == nil else { print("Current place error: \(error?.localizedDescription ?? "")") return } guard let place = placeLikelihoods?.first?.place else { strongSelf.nameLabel.text = "No current place" strongSelf.addressLabel.text = "" return } strongSelf.nameLabel.text = place.name strongSelf.addressLabel.text = place.formattedAddress } } }
Objective-C
#import "GetStartedViewController.h" @import GooglePlaces; @interface GetStartedViewController () // Add a pair of UILabels in Interface Builder and connect the outlets to these variables @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (weak, nonatomic) IBOutlet UILabel *addressLabel; @end @implementation GetStartedViewController { GMSPlacesClient *_placesClient; } - (void)viewDidLoad { [super viewDidLoad]; _placesClient = [GMSPlacesClient sharedClient]; } // Add a pair of UILabels in Interface Builder and connect the outlets to these variables. - (IBAction)getCurrentPlace:(UIButton *)sender { GMSPlaceField placeFields = (GMSPlaceFieldName | GMSPlaceFieldFormattedAddress); __weak typeof(self) weakSelf = self; [_placesClient findPlaceLikelihoodsFromCurrentLocationWithPlaceFields:placeFields callback:^(NSArray<GMSPlaceLikelihood *> * _Nullable likelihoods, NSError * _Nullable error) { __typeof__(self) strongSelf = weakSelf; if (strongSelf == nil) { return; } if (error != nil) { NSLog(@"An error occurred %@", [error localizedDescription]); return; } GMSPlace *place = likelihoods.firstObject.place; if (place == nil) { strongSelf.nameLabel.text = @"No current place"; strongSelf.addressLabel.text = @""; return; } strongSelf.nameLabel.text = place.name; strongSelf.addressLabel.text = place.formattedAddress; }]; } @end
Next steps
After your project is configured, you can explore the sample apps. You'll need Cocoapods v1.6.1 installed.