0

I am using GMSMapview to display the polyline. If I use self.view it's worked perfect.

 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

But while I used GMSMapView as subview to display the polyline it's not getting updated.

@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

Mohanmoorthy
  • 129
  • 5

1 Answers1

0

Are you sure the GMSMapView is fully loaded when you are setting map to polyline?

Implement GMSMapViewDelegate method and do the same, I am sure you would be able to see.

/**
 * Called when all tiles have been loaded (or failed permanently) and labels have been rendered.
 */
optional public func mapViewDidFinishTileRendering(mapView: GMSMapView!)
Prabhu.Somasundaram
  • 1,380
  • 10
  • 13