Das GitHub enthält Beispiele, die die Verwendung des Maps SDK for iOS in Ihrer iOS-App veranschaulichen. Die Beispiel-App enthält Code für die wichtigsten Funktionen des SDK und kann als Ausgangspunkt für Ihre App verwendet werden.
Maps SDK for iOS – Beispiel-App-Liste
Die wichtigsten Beispielaktivitäten aus der Demo-App werden im Folgenden aufgeführt. Außerdem können Sie sie auf den verlinkten Seiten schnell nachschlagen. Eine vollständige Liste der verfügbaren Beispiele finden Sie im Beispielordner auf GitHub.
Die Beispiel-App für das Maps SDK for iOS ist als Downloadarchiv auf GitHub verfügbar. So installieren Sie die Maps SDK for iOS-Beispiel-App und probieren sie aus:
Führen Sie git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.git aus, um das Beispiel-Repository in ein lokales Verzeichnis zu klonen.
Öffnen Sie ein Terminalfenster, wechseln Sie zu dem Verzeichnis, in dem Sie die Beispieldateien geklont haben, und rufen Sie das Verzeichnis „GoogleMaps“ auf:
Swift
cd maps-sdk-for-ios-samples-main/GoogleMaps-Swift pod installopen GoogleMapsSwiftDemos.xcworkspace
Objective-C
cd maps-sdk-for-ios-samples-main/GoogleMaps pod installopen GoogleMapsDemos.xcworkspace
Drücken Sie in Xcode auf die Schaltfläche „Kompilieren“, um die App mit dem aktuellen Schema zu erstellen. Beim Erstellen tritt ein Fehler auf, der Sie auffordert, Ihren API-Schlüssel in die Datei SDKConstants.swift für Swift oder in die Datei SDKDemoAPIKey.h für Objective-C einzugeben.
Bearbeiten Sie die Datei SDKConstants.swift für Swift oder die Datei SDKDemoAPIKey.h für Objective-C und fügen Sie Ihren API-Schlüssel in die Definition der Konstanten apiKey oder kAPIKey ein. Beispiel:
Swift
staticletapiKey="YOUR_API_KEY"
Objective-C
staticNSString*constkAPIKey=@"YOUR_API_KEY";
Entfernen Sie in der Datei SDKConstants.swift (Swift) oder SDKDemoAPIKey.h (Objective-C) die folgende Zeile, da sie zum Registrieren des nutzerdefinierten Problems verwendet wird:
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-07-26 (UTC)."],[[["\u003cp\u003eThe Maps SDK for iOS provides a sample app with code examples showcasing key features, serving as a starting point for your iOS app development.\u003c/p\u003e\n"],["\u003cp\u003eYou can find a comprehensive list of samples in the GitHub repository and easily access specific feature implementations through provided links.\u003c/p\u003e\n"],["\u003cp\u003eTo run the full sample app locally, clone the repository, install dependencies using CocoaPods, and build the project in Xcode after configuring your API key.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting 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.\u003c/p\u003e\n"]]],["The provided content focuses on using the Maps SDK for iOS. Key actions include cloning the sample app repository from GitHub, building the app in Xcode, and integrating an API key. The API key is obtained from the Google Cloud console. After entering the API key, you can build and run the project. You then can interact with the various features demonstrated, like displaying a basic map, adding markers, drawing shapes, enabling location, and handling events. Finally, the content mentions the necessity to grant the app location access.\n"],null,["Select platform: [Android](/maps/documentation/android-sdk/examples \"View this page for the Android platform docs.\") [iOS](/maps/documentation/ios-sdk/examples \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/examples \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nThe Maps SDK for iOS repository on\n[GitHub](https://github.com/googlemaps-samples/maps-sdk-for-ios-samples/tree/main/GoogleMaps)\ncontains samples illustrating the use of the Maps SDK for iOS\nin your iOS app. The sample app contains code for feature highlights of the SDK,\nand can be used starting point for your app.\n| **Troubleshooting:** If the sample app runs successfully but you don't see a map, check that you've added your API key to the app's manifest file, as described in [Using API Keys](/maps/documentation/ios-sdk/get-api-key).\n\nMaps SDK for iOS samples list\n\nKey sample activities from the demo app are listed below and reproduced at the\nlinked pages for quick reference. See the GitHub [samples\nfolder](https://github.com/googlemaps-samples/maps-sdk-for-ios-samples/tree/main/GoogleMaps/GoogleMapsDemos/Samples)\nfor the full list of available samples.\n\n- [Display a basic map](/maps/documentation/ios-sdk/examples/basic-map)\n- [Display an info window for a marker](/maps/documentation/ios-sdk/examples/info-window-marker)\n- [Add a marker to a map](/maps/documentation/ios-sdk/examples/add-marker)\n- [Reverse geocode a location](/maps/documentation/ios-sdk/examples/reverse-geocode)\n- [Enable and disable map gestures](/maps/documentation/ios-sdk/examples/enable-disable-gestures)\n- [Handle marker events](/maps/documentation/ios-sdk/examples/handle-marker-events)\n- [Enable the My Location Button](/maps/documentation/ios-sdk/examples/enable-my-location)\n- [Draw polygons on a map](/maps/documentation/ios-sdk/examples/draw-polygons)\n- [Draw polylines on a map](/maps/documentation/ios-sdk/examples/draw-polylines)\n\nRun the full sample app locally\n\nThe Maps SDK for iOS sample app is available as a\n[download archive](https://github.com/googlemaps-samples/maps-sdk-for-ios-samples/archive/main.zip)\nfrom [GitHub](https://github.com/googlemaps-samples/maps-sdk-for-ios-samples/tree/main/GoogleMaps).\nFollow these steps to install and try the Maps SDK for iOS sample app.\n\n1. Run `git clone https://github.com/googlemaps-samples/maps-sdk-for-ios-samples.git` to clone the samples repository into a local directory.\n2. Open a terminal window, navigate to the directory where you cloned the sample files, and\n drill down into the GoogleMaps directory:\n\n Swift \n\n cd maps-sdk-for-ios-samples-main/GoogleMaps-Swift\n pod install\n open GoogleMapsSwiftDemos.xcworkspace\n\n Objective-C \n\n cd maps-sdk-for-ios-samples-main/GoogleMaps\n pod install\n open GoogleMapsDemos.xcworkspace\n\n3. In Xcode, press the compile button to [build the app](https://developer.apple.com/documentation/xcode/building-and-running-an-app) with the current scheme. The build produces an error, prompting you to enter your API key in the `SDKConstants.swift` file for Swift or`SDKDemoAPIKey.h` file for Objective-C.\n4. [Get an API key](/maps/documentation/ios-sdk/get-api-key) from your project with the [Maps SDK for iOS enabled](/maps/documentation/ios-sdk/cloud-setup#enabling-apis).\n5. Edit the `SDKConstants.swift` file for Swift or`SDKDemoAPIKey.h` file for Objective-C and paste your API key into the definition of either the `apiKey` or `kAPIKey` constant. For example: \n\n Swift \n\n ```swift\n static let apiKey = \"YOUR_API_KEY\"\n ```\n\n Objective-C \n\n ```objective-c\n static NSString *const kAPIKey = @\"YOUR_API_KEY\";\n ```\n6. In the `SDKConstants.swift` file (Swift) or`SDKDemoAPIKey.h` file (Objective-C), remove the following line, because it's used to register the user-defined issue: \n\n Swift \n\n ```swift\n #error (Register for API Key and insert here. Then delete this line.)\n ```\n\n Objective-C \n\n ```objective-c\n #error Register for API Key and insert here.\n ```\n7. Build and run the project. The iOS simulator window appears, showing a list of **Maps SDK Demos**.\n8. Choose one of the options displayed, to experiment with a feature of the Maps SDK for iOS.\n9. If prompted to allow GoogleMapsDemos to access your location, choose **Allow**."]]