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
在 Xcode 中,按下“编译”按钮,使用当前方案构建应用。构建会产生错误,提示您在 Swift 的 SDKConstants.swift 文件或 Objective-C 的 SDKDemoAPIKey.h 文件中输入 API 密钥。
如果您还没有 API 密钥,请按照说明在 Google Cloud 控制台中设置项目并获取 API 密钥。在 Cloud 控制台中配置密钥时,您可以将密钥限制为示例应用的软件包标识符,以确保只有您的应用可以使用该密钥。SDK 示例应用的默认软件包标识符为 com.example.GoogleMapsDemos。
针对 Swift 修改 SDKConstants.swift 文件,针对 Objective-C 修改 SDKDemoAPIKey.h 文件,然后将您的 API 密钥粘贴到 apiKey 或 kAPIKey 常量的定义中。例如:
[null,null,["最后更新时间 (UTC):2025-02-25。"],[[["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 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"]]