【发布时间】:2017-10-15 09:18:37
【问题描述】:
我是 iOS 开发的新手,我正在尝试使用 Google Maps SDK 开发一个简单的应用程序。我正在按照Google Maps Getting Started guide 中列出的步骤进行操作。
我见过类似的问题: Google Maps iOS SDK Integration not loading maps 问题出在捆绑 ID 上。我确定不是我的情况。
我已经花了 3 天时间从头开始尝试新应用。
我创建了一个新的 api 密钥,添加了我的包 ID。
-
我添加了 API 密钥:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. GMSServices.provideAPIKey("MYKEY") return true } -
下面是 ViewController.swift:
import UIKit import GoogleMaps class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0) let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) view = mapView let marker = GMSMarker() marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20) marker.title = "Sydney" marker.snippet = "Australia" marker.map = mapView } }
我在模拟器和真机上运行它。 我得到了标记和谷歌标志,但没有地图。谁能提供一些线索?
【问题讨论】:
-
您是否下载了GoogleInfo.plist并添加到您项目中的目标中?
-
它们是您代码中的问题。一是您正在设置地图的矩形,二是您必须将地图添加为子视图。你可以按照这个教程raywenderlich.com/109888/google-maps-ios-sdk-tutorial
-
感谢指点 - 我没有添加 .plist 并且我只是在关注谷歌入门指南。我会尝试你的建议,并会回来..
-
@Aks,我没有使用 firebase。我没有找到如何为谷歌地图获取 GoogleService-Info.plist。
-
@Waqas,您发送的链接似乎很旧,我在对象库中找不到 MapViewController。我认为它与 api 密钥有关,有什么方法可以在谷歌控制台中调试正在接收的内容以及遇到的错误?
标签: ios swift google-maps google-maps-sdk-ios