ios - 谷歌地图不显示关于 xcode8.2 的新版本

标签 ios swift google-maps swift3

我尝试将 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/

相关文章:

android - 如何制作 map 对象(例如 : circle) clickable in android google maps v2?

objective-c - MPMoviePlayerController 中的 360 度视频

ios - ViewController 中的顶部栏 ios swift 显示上一个顶部栏

ios - "res"代表什么?

android - 另一个 Google Android Maps API v2 身份验证问题

jquery - Google map 多边形渲染不正确

objective-c - Facebook 登录对话框不适用于 UIAlertView,但适用于 UIButton

ios - 在 Storyboard本身中将自定义类添加到 UILabel 时如何查看更改?

ios - 如何使用 AFNetworking 检索 JSON 多数据?

swift - 如何确定 Swift 循环是否被中断