我是iOS开发新手,正在尝试使用Google Maps SDK的简单应用。我遵循Google Maps Getting Started guide上列出的步骤。谷歌地图iOS SDK:地图不加载
我看到了类似的问题: Google Maps iOS SDK Integration not loading maps 问题出在bundle 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 } }
我跑它在模拟器和真正的手机。 我得到标记和Google徽标,但没有地图。有人能提供一些线索吗?
您是否已下载GoogleInfo.plist并将其添加到项目中的目标? – Aks
他们在你的代码中存在问题。一个是你设置地图的矩形,另一个是你必须添加地图作为子视图。你可以按照这个教程 https://www.raywenderlich.com/109888/google-maps-ios-sdk-tutorial –
感谢指针 - 我没有添加.plist,我只是按照谷歌入门指南。我会尝试你的建议,并会回来.. – kal