2017-02-22 44 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

啊是的,我错过了,现在的作品,非常感谢 –