2016-10-03 10 views
0

我決定在故事板中創建一個視圖並將其類定義爲GMSMapView。然後我創建了一個IBOutlet到我的ViewController類。從故事板添加GMSMapView時獲取nil

但是,當我嘗試將攝像機添加到我的GMSMapView,我得到的IBOutlet對象中的零值:

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

發生了什麼事?

+1

你在哪裏寫代碼?嘗試在viewDidLoad中編寫它。直到您訪問時纔可以設置插座。 – PGDev

+0

我正在寫'viewDidLoad' –

+0

@JaysonTamayo你可以鞋代碼嗎? –

回答

0

試試這個代碼..

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_) 
+0

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_) –