从故事板添加GMSMapView时获取nil
我决定在故事板中创建一个视图并将其类定义为GMSMapView
。然后我创建了一个IBOutlet
到我的ViewController
类。从故事板添加GMSMapView时获取nil
但是,当我尝试将摄像机添加到我的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_)
var mapView_:GMSMapView! VAR相机= GMSCameraPosition.camera(withLatitude:centerLat,经度:centerLng,缩放:centerZoom) mapView_ = GMSMapView.map(withFrame:self.allplacemapview.bounds,相机:相机) mapView_.mapType = kGMSTypeNormal 变种startLoc = CLLocationCoordinate2DMake (theAppDelegate.lang,theAppDelegate.long1) self.setMarker(mapView_,imageName:“startPoint.png”,location:startLoc,titleString:“当前位置”) self.allplacemapview.addSubview(mapView_) –
你在哪里写代码?尝试在viewDidLoad中编写它。直到您访问时才可以设置插座。 – PGDev
我正在写'viewDidLoad' –
@JaysonTamayo你可以鞋代码吗? –