问题
I try to use the Google Maps SDK for iOS with the Swift and Xcode 8.2.
I had set the API Key correct.
I using the Google Map SDK website sample code.
let camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
let mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
myView = mapView
It will show the errors:
'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'
So I change the to like below:
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
But the google map is still not display.
Have anyone known where is the problem?
Thank you very much.
回答1:
The problem is you have initialized mapView
with CGRect.zero
so the frame is (0.0, 0.0, 0.0, 0.0)
means 0 width
and 0 height
, instead of that set the frame
properly like your view.bounds
.
let mapView = GMSMapView.map(withFrame: self.view.bounds, camera: camera)
回答2:
Have your Enable API at API Consol
来源:https://stackoverflow.com/questions/41157184/google-maps-not-display-about-new-version-with-xcode8-2