GMSMapView在用作子视图时不显示折线

时间:2016-11-22 13:38:38

标签: ios swift gmsmapview

我正在使用GMSMapview显示折线。如果我使用self.view它是完美的。

 let camera = GMSCameraPosition.camera(withLatitude: 0, longitude:-165, zoom:2)
            let mapView = GMSMapView.map(withFrame: self.gMap.bounds, camera:camera)

            let path = GMSMutablePath()
            path.addLatitude(-33.866, longitude:151.195) // Sydney
            path.addLatitude(-18.142, longitude:178.431) // Fiji
            path.addLatitude(21.291, longitude:-157.821) // Hawaii
            path.addLatitude(37.423, longitude:-122.091) // Mountain View

            let polyline = GMSPolyline(path: path)
            polyline.strokeColor = UIColor.blue
            polyline.strokeWidth = 5.0
            polyline.map = mapView

            self.gMap.isHidden = true
            self.view = mapView

enter image description here

但是当我使用GMSMapView作为子视图来显示折线时,它没有得到更新。

@IBOutlet weak var gMap: GMSMapView!

            let camera = GMSCameraPosition.camera(withLatitude: 0, longitude:-165, zoom:2)
            let mapView = GMSMapView.map(withFrame: self.gMap.bounds, camera:camera)

            let path = GMSMutablePath()
            path.addLatitude(-33.866, longitude:151.195) // Sydney
            path.addLatitude(-18.142, longitude:178.431) // Fiji
            path.addLatitude(21.291, longitude:-157.821) // Hawaii
            path.addLatitude(37.423, longitude:-122.091) // Mountain View

            let polyline = GMSPolyline(path: path)
            polyline.strokeColor = UIColor.blue
            polyline.strokeWidth = 5.0
            polyline.map = mapView

            //self.gMap.isHidden = true
            self.gMap = mapView

enter image description here

1 个答案:

答案 0 :(得分:0)

在将地图设置为折线时,您确定GMSMapView已完全加载吗?

实施GMSMapViewDelegate方法并执行相同操作,我相信您能够看到。

/**
 * Called when all tiles have been loaded (or failed permanently) and labels have been rendered.
 */
optional public func mapViewDidFinishTileRendering(mapView: GMSMapView!)