Maps SDK for iOS sample code Stay organized with collections Save and categorize content based on your preferences.
Page Summary
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.
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.
- Display a basic map
- Display an info window for a marker
- Add a marker to a map
- Reverse geocode a location
- Enable and disable map gestures
- Handle marker events
- Enable the My Location Button
- Draw polygons on a map
- Draw polylines on a map
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.- Run
git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.gitto clone the samples repository into a local directory. 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-Swift
open GoogleMapsSwiftXCFrameworkDemos.xcodeprojObjective-C
cd maps-sdk-for-ios-samples-main/GoogleMaps
open GoogleMapsDemos.xcodeproj- In the Xcode project, go toFile >Add Package Dependencies. Enter
https://github.com/googlemaps/ios-maps-sdkas the URL, pressEnter to pull in the package, and clickAdd Package. - 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 the
SDKConstants.swiftfile for Swift orSDKDemoAPIKey.hfile for Objective-C. - Get an API key from your project with theMaps SDK for iOS enabled.
- Edit the
SDKConstants.swiftfile for Swift orSDKDemoAPIKey.hfile for Objective-C and paste your API key into the definition of either theapiKeyorkAPIKeyconstant. For example:Swift
staticletapiKey="YOUR_API_KEY"
Objective-C
staticNSString*constkAPIKey=@"YOUR_API_KEY";
- In the
SDKConstants.swiftfile (Swift) orSDKDemoAPIKey.hfile (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. - Build and run the project. The iOS simulator window appears, showing a list ofMaps SDK Demos.
- Choose one of the options displayed, to experiment with a feature of the Maps SDK for iOS.
- 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.