Maps SDK for iOS sample code

  • The Maps SDK for iOS provides a sample app with code examples showcasing key features, serving as a starting point for your iOS app development.

  • You can find a comprehensive list of samples in the GitHub repository and easily access specific feature implementations through provided links.

  • To run the full sample app locally, clone the repository, install dependencies using CocoaPods, and build the project in Xcode after configuring your API key.

  • Troubleshooting steps are available if you encounter issues like not seeing a map after successfully running the app, guiding you to add your API key correctly.

Select platform:AndroidiOSJavaScript

The Maps SDK for iOS repository onGitHubcontains samples illustrating the use of the Maps SDK for iOSin your iOS app. The sample app contains code for feature highlights of the SDK,and can be used starting point for your app.

Troubleshooting:If the sample app runs successfully but youdon't see a map, check that you've added your API key to the app's manifest file, as described inUsing API Keys.

Maps SDK for iOS samples list

Key sample activities from the demo app are listed below and reproduced at thelinked pages for quick reference. See the GitHubsamplesfolderfor the full list of available samples.

Run the full sample app locally

The Maps SDK for iOS sample app is available as adownload archivefromGitHub.Follow these steps to install and try the Maps SDK for iOS sample app.

Important: You must remove any existing dependencies added using CocoaPods or manually. SeeStep 2 of Set up an Xcode project for instructions.
  1. Rungit clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.git to clone the samples repository into a local directory.
  2. Open a terminal window, navigate to the directory where you cloned the sample files, and drill down into the GoogleMaps directory:

    Swift

    cd maps-sdk-for-ios-samples/GoogleMaps-Swiftopen GoogleMapsSwiftXCFrameworkDemos.xcodeproj

    Objective-C

    cd maps-sdk-for-ios-samples-main/GoogleMapsopen GoogleMapsDemos.xcodeproj
  3. In the Xcode project, go toFile >Add Package Dependencies. Enterhttps://github.com/googlemaps/ios-maps-sdk as the URL, pressEnter to pull in the package, and clickAdd Package.
  4. In Xcode, press the compile button tobuild the app with the current scheme. The build produces an error, prompting you to enter your API key in theSDKConstants.swift file for Swift orSDKDemoAPIKey.h file for Objective-C.
  5. Get an API key from your project with theMaps SDK for iOS enabled.
  6. Edit theSDKConstants.swift file for Swift orSDKDemoAPIKey.h file for Objective-C and paste your API key into the definition of either theapiKey orkAPIKey constant. For example:

    Swift

    staticletapiKey="YOUR_API_KEY"

    Objective-C

    staticNSString*constkAPIKey=@"YOUR_API_KEY";
  7. In theSDKConstants.swift file (Swift) orSDKDemoAPIKey.h file (Objective-C), remove the following line, because it's used to register the user-defined issue:

    Swift

    #error(RegisterforAPIKeyandinserthere.Thendeletethisline.)

    Objective-C

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

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.