2017-02-22 39 views
1

全屏這是當前的代碼,使編輯建議後,就不再顯示在地圖悉尼澳大利亞谷歌地圖API中SWIFT3

類LocateVC上的標記:的UIViewController {

@IBOutlet weak var mapView: GMSMapView! 

override func viewDidLoad() { 
    super.viewDidLoad() 
    //override func loadView() { 
    // Create a GMSCameraPosition that tells the map to display the 
    // coordinate -33.86,151.20 at zoom level 6. 
    let camera = GMSCameraPosition.camera(withLatitude: -33.86 , longitude: 151.20, zoom: 6.0) 
    let mapView = GMSMapView.map(withFrame: self.mapView.bounds, camera: camera) 
    self.mapView = mapView 

    // Creates a marker in the center of the map. 
    let marker = GMSMarker() 
    marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20) 
    marker.title = "Sydney" 
    marker.snippet = "Australia" 
    marker.map = mapView 
    } 

}

輸出

這是加載 This is the screen that loads

屏幕

而且在澳大利亞悉尼 And no marker on Sydney Australia

回答

0

你正在設置mapviewviewViewController

因此改變你的這兩條線

let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera) 
view = mapView 

在沒有標記:

let mapView = GMSMapView.map(withFrame: self.mapView.bounds, camera: camera) 
self.mapView = mapView 
+0

好的,做到了。這現在給了我一個致命的錯誤:意外地發現零時,加載地圖時解包可選值 –

+0

@JadeReynolds檢查你的'mapView'插座是否正確連接到'LocateVC',如果沒有連接它。 –

+0

啊是的,我錯過了,現在的作品,非常感謝 –