我决定在情节提要中创建一个视图,并将其类定义为GMSMapView。然后,为我的IBOutlet类创建了一个ViewController

但是,当我尝试将摄像机添加到我的GMSMapView时,我在IBOutlet对象中得到一个零值:

let camera: GMSCameraPosition = GMSCameraPosition.camera(withLatitude: 48.857165, longitude: 2.354613, zoom: 8.0)
newMapView.camera = camera


发生了什么?

最佳答案

试试这个代码。

var mapView_: GMSMapView!
var camera = GMSCameraPosition.camera(withLatitude: centerLat, longitude: centerLng, zoom: centerZoom)
mapView_ = GMSMapView.map(withFrame: self.allplacemapview.bounds, camera: camera)
mapView_.mapType = kGMSTypeNormal
var startLoc = CLLocationCoordinate2DMake(theAppDelegate.lang, theAppDelegate.long1)
self.setMarker(mapView_, imageName: "startPoint.png", location: startLoc, titleString: "Current Location")
self.allplacemapview.addSubview(mapView_)

关于ios - 从 Storyboard 添加GMSMapView时获取零,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39824161/

10-11 04:28