Search code examples
swiftgoogle-mapslatitude-longitudepolyline

Swift Encode Lat&Lon to Polyline


I have a list of lat&lon, want to show it on map as a path. I could show polyline on the map by using GMSPath(fromEncodePath: polyline).

How could I convert lat&lon list as a polyline or display it on the map?

Much appreciated!


Solution

  • You can create a path from coordinates like this

    let path = GMSMutablePath()
    path.add(CLLocationCoordinate2DMake(29.520,30.856))
    path.add(CLLocationCoordinate2DMake(25.17,40.1235))
    let pLine = GMSPolyline.init(path: path)