Setup and Demo

Select platform: Android iOS

This page describes how to set up the utility library for the Maps SDK for iOS.

To try these utilities, you can either:

Optionally install CocoaPods

The utility library is available as aCocoaPodspod named Google-Maps-iOS-Utils.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:

sudo gem install cocoapods

For details, see theCocoaPods Getting Started guide.

Install and run the demo app

The utility library includes a demo app that you can install and then try out each utility.

Install the demo app by using one of these two methods:

Use files from GitHub

  1. Download the code sample archivefrom 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 appropriate samples directory for the language you want to use:
    • For Swift, runcd google-maps-ios-utils-master/samples/SwiftDemoApp
    • For Objective-C, runcd google-maps-ios-utils-master/samples/ObjCDemoApp
  3. Run the following command:
    pod install
  4. Close Xcode, and then open (double-click) your project's .xcworkspacefile to launch Xcode. From this time onwards, you must use the.xcworkspacefile to open the project.

Use CocoaPods v1.6.1

  1. Open a terminal window and install version 1.6.1:
    sudo gem install cocoapods -v1.6.1
  2. Fetch the Google Maps files using Cocoapods:
    pod try Google-Maps-iOS-Utils

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

Add the API key to the demo app

InGet an API key,you generate an API key for your app. Now add that key to the Xcode project for the demo app.

Swift

Add your API key to yourAppDelegate.swiftas follows:

  1. Add the following import statement:
    import GoogleMaps
  2. Edit the following line to add your API key between the double quotes:
    // Change this key to a valid key registered with the demo app bundle id.
    let mapsAPIKey = ""

Objective-C

Add your API key to yourAppDelegate.mas follows:

  1. Add the following import statement:
    @import GoogleMaps;
  2. Edit the following line to add your API key between the double quotes:
    // Change this key to a valid key registered with the demo app bundle id.
    static NSString *const kMapsAPIKey = @ "";

Build and run the demo app

After you add the API key, build and run the project:

  • If you are running the Swift version of the demo, you can select which utility to view in the app.
  • If you are running the Objective-C version of the demo, you see the demo of the marker clustering utility. You can then edit the Objective-C version of the demo to try each utility. See theAdd a utility to your appsection below for more information.

Install the utility library as an Xcode project

Follow these steps to add the utility library to your Xcode workspace:

Use CocoaPods

  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 aSingle View Application.)
  2. If you don't already have a pod file for your project, create a file namedPodfilein your project directory. This file defines your project's dependencies.
  3. Edit your project's pod file and add a dependency on the Google-Maps-iOS-Utilspod. Here is an example which includes the dependencies you need for the Maps SDK for iOS and the utility library:
    source 'https://github /CocoaPods/Specs.git'
    platform:ios, '13.0'
    
    target 'YOUR_APPLICATION_TARGET_NAME_HERE' do
    use_frameworks!
    pod 'GoogleMaps', '7.4.0'
    pod 'Google-Maps-iOS-Utils', '4.2.2'
    end
  4. Runpod install.
  5. Close Xcode, and then open (double-click) your project's .xcworkspacefile to launch Xcode. From this time onwards, you must use the.xcworkspacefile to open the project.

Note:The marker clustering utility is dependent on the quadtree, but you can use the quadtree without marker clustering. If you want only the quadtree utility, you can change pod 'Google-Maps-iOS-Utils'to 'Google-Maps-iOS-Utils/QuadTree'in your pod file.

Use Carthage

  1. Install Carthage. There are several methods, so see the Carthage README filefor exact steps.
  2. 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 theiOS App template.In Xcode 11.7 or earlier, create aSingle View Application.)
  3. Create a file namedCartfilein your project directory. This file defines your project's dependencies.
  4. Edit theCartfileand add the Maps SDK for iOS Utility Library dependency:
    github "googlemaps/google-maps-ios-utils"
  5. Save theCartfile.
  6. In a terminal window, go to the directory containing theCartfile:
    cd <path-to-project>
  7. Run the update command:
    carthage update --platform iOS

    This will install the APIs specified in theCartfile,along with any dependencies they may have.
  8. In the Finder, in your project directory, go to the downloaded framework files underCarthage/Build/iOS.
  9. Add the Maps SDK for iOS frameworks into your project by dragging the following bundles into your project. (When prompted, selectCopy items if needed, please use the same version as above.)
    • GoogleMaps-x.x.x/Base/Frameworks/GoogleMapsBase.framework
    • GoogleMaps-x.x.x/Maps/Frameworks/GoogleMaps.framework
    • GoogleMaps-x.x.x/Maps/Frameworks/GoogleMapsCore.framework
    • GoogleMaps-x.x.x/Maps/Frameworks/GoogleMapsUtils.framework
  10. Right-clickGoogleMaps.frameworkin your project, and selectShow In Finder.
  11. Drag theCarthage/Build/iOS/GoogleMaps.framework/Resources/GoogleMaps.bundlefrom the Resourcesfolder into your project. When prompted, ensureCopy items into destination group's folderisnotselected.
  12. Select your project from the Project Navigator, and choose your application's target.
  13. Open theBuild Phasestab for your application’s target, and withinLink Binary with Libraries,add the following frameworks:
    • Accelerate.framework
    • CoreData.framework
    • CoreGraphics.framework
    • CoreImage.framework
    • CoreLocation.framework
    • CoreTelephony.framework
    • CoreText.framework
    • GLKit.framework
    • ImageIO.framework
    • libc++.tbd
    • libz.tbd
    • OpenGLES.framework
    • QuartzCore.framework
    • SystemConfiguration.framework
    • UIKit.framework
  14. Choose your project, rather than a specific target, and open the Build Settingstab. In theOther Linker Flagssection, add-ObjC.If these settings are not visible, change the filter in theBuild Settingsbar fromBasictoAll.

Use Swift Package Manager

  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 new project and select theiOS App template.On Xcode 11.7 or older, create aSingle View Application.)
  2. Add the Maps SDK for iOS as a dependency. See Installing the SDKfor options.
  3. In your Xcode project, navigate toFile->Swift Packages ->Add Package Dependency.
  4. In the presented window, enter the Maps SDK for iOS Utility Library repository URL https://github /googlemaps/google-maps-ios-utilsand selectNext.
  • At this point, you may be prompted to authenticate with your GitHub account. Follow the instructions to create a GitHub personal access tokento continue the process.
  • In the next window, select theVersionradio option, selectExact from the dropdown list, enter the latest version of the Maps SDK for iOS Utility Library (e.g. "3.4.0" ) and selectNext.
  • Add the API key to your app

    SeeSet up an Xcode Projectfor instructions on generating an API key and adding it to your Xcode project.

    Build and run the project

    After you add the API key, build and run the project.

    Add a utility to your app

    See the documentation on each utility for more information on using it in your app: