Search code examples
iosswiftgoogle-maps-sdk-ios

How to draw line on google maps


I have so many coordinates of a user from server and I want draw line to connect those like this.

I've tried to use This way but my app get crash, I guess this happend because i send too many request.


Solution

  • The simplest way is to use a GMSPolyline.

    Assuming you have a coordinates array of CLLocationCoordinate2D's and they are in the correct order.

    let path = GMSMutablePath()
    for coord in coordinates {
        path.add(coord)
    }
    let line = GMSPolyline(path: path)
    line.strokeColor = UIColor.blue
    line.strokeWidth = 3.0
    line.map = self.map