Google地图不会显示xcode8.2的新版本
我尝试使用Swift和Xcode 8.2的iOS版Google Maps SDK。
我已经设置了正确的API密钥。
我使用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 :)'已被重命名为'camera(withLitude:longitude:zoom :)'
swift:84:47:'CGRectZero'在Swift中不可用
swift:85:17:'myLocationEnabled'已被重命名为'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
,所以frame是(0.0, 0.0, 0.0, 0.0)
CGRect.zero
(0.0, 0.0, 0.0, 0.0)
意思是0 width
和0 height
,而不是像你的view.bounds
那样设置frame
。
let mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
在API Consol上使用您的启用API