我尝试将 Google Maps SDK for iOS 与 Swift 和 Xcode 8.2 结合使用。
我已正确设置 API key 。
我使用的是 Google Map SDK 网站示例代码。
let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
myView = mapView
它将显示错误:
'cameraWithLatitude(_:longitude:zoom:)' has been renamed to 'camera(withLatitude:longitude:zoom:)'
swift:84:47: 'CGRectZero' is unavailable in Swift
swift:85:17: 'myLocationEnabled' has been renamed to 'isMyLocationEnabled'
所以我将其更改为如下所示:
let camera = GMSCameraPosition.camera(withLatitude: -33.86,
longitude: 151.20, zoom: 6)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
myView.isMyLocationEnabled = true
myView = mapView
但是谷歌地图还是没有显示。
有人知道问题出在哪里吗?
非常感谢。
最佳答案
问题是你已经用 CGRect.zero
初始化了 mapView
所以框架是 (0.0, 0.0, 0.0, 0.0)
意味着 0 宽度
和 0 高度
,而不是像您的 view.bounds
那样正确设置 frame
。
let mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
关于ios - 谷歌地图不显示关于 xcode8.2 的新版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41157184/