我尝试将与Swift和Xcode 8.2一起用于iOS。
我已将API键设置为正确。
我使用Google网站示例代码。
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:)”已改名为“照相机”(纬度:经度:缩放:) swift:84:47:“CGRectZero”在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但谷歌地图仍未显示。
有人知道问题出在哪里吗?
非常感谢。
发布于 2016-12-15 05:50:16
问题是您已经用CGRect.zero初始化了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)发布于 2016-12-15 05:55:05
https://stackoverflow.com/questions/41157184
复制相似问题