Code Samples Overview

Select platform: Android iOS JavaScript

The SDK demo app supplied with the Maps SDK for iOS includes samples for the feature highlights of the SDK. Examine the code in the demo app to see how each sample is implemented.

Try the SDK demos

The Maps SDK for iOS SDK demo app is available as a download archive from GitHub and as a CocoaPods pod. CocoaPods is an open source dependency manager for Swift and Objective-C Cocoa projects.

Follow these steps to install and try the Maps SDK for iOS SDK demo app.

  1. Get the sample files using one of these two methods:

    Directly from GitHub

    1. Download the code sample archive from GitHub and unpack the archive.
    2. Open a terminal window, navigate to the directory where you expanded the sample files, and drill down into the GoogleMaps directory:


      cd maps-sdk-for-ios-samples-main/GoogleMaps-Swift


      cd maps-sdk-for-ios-samples-main/GoogleMaps
    3. Run the following commands:


      pod install
      open GoogleMapsSwiftDemos.xcworkspace


      pod install
      open GoogleMapsDemos.xcworkspace

    Use CocoaPods v1.6.1

    1. If you don't already have the CocoaPods tool, install version 1.6.1 on macOS by running the following command from the terminal. For details, see the CocoaPods Getting Started guide.
      sudo gem install cocoapods -v1.6.1
    2. Fetch the Google Maps files using Cocoapods:
      pod try GoogleMaps

      Choose either Swift or Objective-C when prompted. CocoaPods updates your spec repositories, then opens the demo in a temporary Xcode project named SwiftDemoApp.xcodeproj or ObjCDemoApp.xcodeproj.

  2. In Xcode, press the compile button to build and then run the current scheme. The build produces an error, prompting you to enter your API key in the SDKConstants.swift file for Swift orSDKDemoAPIKey.h file for Objective-C.
  3. If you don't yet have an API key, follow the instructions to set up a project on the Google Cloud Console and get an API key. When configuring the key on the Cloud 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 com.example.GoogleMapsDemos.
  4. Edit the SDKConstants.swift file for Swift orSDKDemoAPIKey.h file for Objective-C and paste your API key into the definition of either the apiKey or kAPIKey constant. For example:


    static let apiKey = "YOUR_API_KEY"


    static NSString *const kAPIKey = @"YOUR_API_KEY";
  5. Remove the following line, because it's used to register the user-defined issue:


    #error (Register for API Key and insert here. Then delete this line.”)


    #error Register for API Key and insert here.
  6. Build and run the project. The iOS simulator window appears, showing a list of Maps SDK Demos.
  7. Choose one of the options displayed, to experiment with a feature of the Maps SDK for iOS.
  8. If prompted to allow GoogleMapsDemos to access your location, choose Allow.

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 map objects, markers, shapes, and other pages in this guide.