МИКОЛА ШАХ
МИКОЛА ШАХ

Reputation: 21

How to draw polygon with radius around polyline in ios swift

I have problem with drawing polygon around polyline(( I have all coordinates polyline and i want to buffer the coordinates to get coordinates of polygon around this polyline.

I have something like this: enter image description here.

But I want to make something like this:

enter image description here

please help...

Upvotes: 2

Views: 2065

Answers (2)

Sanjay Mali
Sanjay Mali

Reputation: 546

If you want to draw polygone on Google map with array coordinates use this function:

func addPloygone(){
        let path = GMSMutablePath()
        path.removeAllCoordinates()
        for i in places{
            path.add(CLLocationCoordinate2D(latitude:i.lon!, longitude:i.lat!))
            let polyline = GMSPolygon(path: path)
            polyline.geodesic = true
            polyline.map = map
            polyline.strokeColor = UIColor.black
            polyline.fillColor = UIColor.init(colorLiteralRed:176/255, green: 143/255, blue:52/255, alpha: 0.6)
        }
    }

Upvotes: 0

Gurdeep
Gurdeep

Reputation: 191

You can just draw 2 polylines with same path.

Let's say you've created a variable thePath with buffered coordinates. You've already created a polyline with this path.

let redPolyline = GMSPolyline()
redPolyline.path = thePath
redPolyline.map = mapview

Create another one.

let redPolyline = GMSPolyline()
redPolyline.path = thePath
redPolyline.strokeWidth = 6.0 // Change it accordingly 
redPolyline.strokeWidth = UIColor.redColor().colorWithAlphaComponent(0.5) // Change it accordingly

redPolyline.map = mapview

Remember to that redPolyline's zIndex should be higher than the bluePolyline because as i can see in the image you've provided, redPolyline is on top of the other one.

Upvotes: 2

Related Questions