Getting Started

Before you can begin working with Google Maps on iOS, you need to download the Google Maps SDK for iOS and ensure that you have an API key.

Complete release notes are available for each release.

Step 1: Get the latest version of Xcode

To build a project using the Google Maps SDK for iOS, you need version 6.3 or later of Xcode.

Step 2: Get CocoaPods

The Google Maps SDK for iOS is available as a CocoaPods pod. 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 OS X by running the following command from the terminal. For details, see the CocoaPods Getting Started guide.

$ sudo gem install cocoapods

Step 3: Install the API using CocoaPods

Create a Podfile for the Google Maps SDK for iOS and use it to install the API and its dependencies:

  1. If you don't have an Xcode project yet, create one now and save it to your local machine. (If you're new to iOS development, create a Single View Application.)
  2. Create a file named Podfile in your project directory. This file defines your project's dependencies, and is commonly referred to as a Podspec.
  3. Edit the Podfile and add your dependencies. Here is a simple Podspec, including the name of the pod you need for the Google Maps SDK for iOS:

    source 'https://github.com/CocoaPods/Specs.git'
    platform :ios, '8.1'
    pod 'GoogleMaps'

  4. Save the Podfile.

  5. Open a terminal and go to the directory containing the Podfile:

    $ cd <path-to-project>

  6. Run the pod install command. This will install the APIs specified in the Podspec, along with any dependencies they may have.

    $ pod install

  7. 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.

Step 4: Get an API key

Follow these steps to enable the necessary APIs on the Google Developers Console. You must enable the Google Maps SDK for iOS, and optionally the Google Places API for iOS. If your project doesn't already have an iOS key (a type of API key), these instructions also help you create a new API key.

  1. Go to the Google Developers Console.
  2. Create or select a project.
  3. Click Continue to enable the Google Maps SDK for iOS API.
    Optionally, you can also enable the Google Places API for iOS now. Alternatively, you can enable the Google Places API for iOS later, if you need it.
  4. On the Credentials page, get an iOS key and set the API credentials.
    Note: If you have an existing iOS key, you may use that key. You can use the same key with any of your iOS applications within the same project.
  5. Enter your app's bundle identifier when prompted. For example: com.example.hellomap.
  6. Click Create.

    Your new iOS key appears in the list of API keys for your project. An API key is a string of characters, something like this:

    AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0

You can also look up an existing key in the Google Developers Console.

For more information, see Developers Console Help.

Step 5: Add the API key to your application

Objective-C

Add your API key to your AppDelegate.m as follows:

  1. Add the following import statement:
    @import GoogleMaps;
  2. Add the following to your application:didFinishLaunchingWithOptions: method, replacing YOUR_API_KEY with your API key:
    [GMSServices provideAPIKey:@"YOUR_API_KEY"];

Swift

Add your API key to your AppDelegate.swift as follows:

  1. Add the following import statement:
    import GoogleMaps
  2. Add the following to your application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) func, replacing YOUR_API_KEY with your API key:
    GMSServices.provideAPIKey("YOUR_API_KEY")

Step 6: Add a map

The code below demonstrates how to add a simple map to an existing ViewController. If you're creating a new app to iOS, first follow the installation instructions above, and create a new Single View Application.

Add or update a few methods inside your app's default ViewController to create and initialize an instance of GMSMapView, as shown in the sample below.

Objective-C

#import "YourViewController.h"
@import GoogleMaps;

@implementation YourViewController {
  GMSMapView *mapView_;
}

- (void)viewDidLoad {
  // Create a GMSCameraPosition that tells the map to display the
  // coordinate -33.86,151.20 at zoom level 6.
  GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86
                                                          longitude:151.20
                                                               zoom:6];
  mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
  mapView_.myLocationEnabled = YES;
  self.view = mapView_;

  // Creates a marker in the center of the map.
  GMSMarker *marker = [[GMSMarker alloc] init];
  marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
  marker.title = @"Sydney";
  marker.snippet = @"Australia";
  marker.map = mapView_;
}

@end

Swift

import UIKit
import GoogleMaps

class YourViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
        longitude: 151.20, zoom: 6)
    let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
    mapView.myLocationEnabled = true
    self.view = mapView

    let marker = GMSMarker()
    marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
    marker.title = "Sydney"
    marker.snippet = "Australia"
    marker.map = mapView
  }
}

Run your application. You should see a map with a single marker centered over Sydney, Australia. If you see the marker, but the map is not visible, confirm that you have provided your API key.

Step 7: Declare the URL schemes used by the API

With iOS 9 and Xcode 7, apps must declare the URL schemes that they intend to open, by specifying the schemes in the app's Info.plist file. The Google Maps SDK for iOS opens the Google Maps mobile app when the user clicks the Google logo on the map, and your app therefore needs to declare the relevant URL schemes.

To declare the URL schemes used by the Google Maps SDK for iOS, add the following lines to your Info.plist:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>googlechromes</string>
    <string>comgooglemaps</string>
</array>

The following screenshot shows the configuration in the Xcode user interface:

LSApplicationQueriesSchemes configuration in Xcode

Without the above declaration, the following errors occur when the user taps the Google logo on the map:

-canOpenURL: failed for URL: "comgooglemaps://" - error: "This app is not allowed to query for scheme comgooglemaps"
-canOpenURL: failed for URL: "googlechromes://" - error: "This app is not allowed to query for scheme googlechromes"

To eliminate these errors, add the declaration to your Info.plist as described above.

Experiment with the Google Maps SDK demo project

Try the SDK demos using pod try GoogleMaps. For more details, see the guide to code samples.

Upgrade from an earlier version

Follow these instructions to upgrade an existing project to the most recent version of the Google Maps SDK for iOS.

If you previously installed the Google Maps SDK for iOS from a zip file containing a static framework:

  1. Remove all references to the previous framework from your Xcode project.
  2. Follow the instructions above to install the Google Maps SDK for iOS using CocoaPods.
  3. Make any necessary changes as a result of the upgrade. See the release notes for a list of the changes in each release.
  4. Clean and rebuild your project by selecting Product > Clean and then Product > Build.

If you previously installed the Google Maps SDK for iOS from the Google-Maps-iOS-SDK pod:

  1. Change your pod name to GoogleMaps.
  2. Run pod install.
  3. Make any necessary changes as a result of the upgrade. See the release notes for a list of the changes in each release.
  4. Clean and rebuild your project by selecting Product > Clean and then Product > Build.

If you previously installed the Google Maps SDK for iOS from the GoogleMaps pod:

  1. Check your Podfile for any version limiter, and ensure you remove or update the version to ensure you get the version you need. See the release notes for a list of version numbers.
  2. Run pod update.
  3. Make any necessary changes as a result of the upgrade. See the release notes for a list of the changes in each release.
  4. Clean and rebuild your project by selecting Product > Clean and then Product > Build.

Send feedback about...

Google Maps SDK for iOS
Google Maps SDK for iOS
Need help? Visit our support page.