How to Draw an Arc on Google Maps in iOS

Draw Straight Line Google Maps iOS

GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
[path addCoordinate:CLLocationCoordinate2DMake(37.45, -122.0)];

GMSPolyline *line = [GMSPolyline polylineWithPath:path];
line.map = mapView_;

how to draw an arc with line using UIBezierPath

Try with this (as you can see, I've used addQuadCurveToPoint a variant of addCurveToPoint proposed by @wain - ask google for addCurveToPoint and switch to picture search to see how it work ) :

-(void) drawRect:(CGRect)rect
{
UIBezierPath * aPath = [UIBezierPath bezierPath];

// Set the starting point of the shape.
[aPath moveToPoint:CGPointMake(CGRectGetMinX(rect), CGRectGetMinY(rect))];

// Draw some lines.
[aPath addLineToPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMinY(rect))];

//changes start here !

//the point look to be at 80% down
[aPath addLineToPoint:CGPointMake(CGRectGetMaxX(rect), CGRectGetMaxY(rect) * .8)];

//1st arc
//The end point look to be at 1/4 at left, bottom
CGPoint p = CGPointMake(CGRectGetMaxX(rect) / 4, CGRectGetMaxY(rect));
CGPoint cp = CGPointMake( (CGRectGetMaxX(rect) / 4) + ((CGRectGetMaxX(rect) - (CGRectGetMaxX(rect) / 4)) / 2) , CGRectGetMaxY(rect) * .8);

[aPath addQuadCurveToPoint:p controlPoint:cp];

//2nd arc
//The end point look to be at 80% downt at left,
CGPoint p2 = CGPointMake(CGRectGetMinX(rect), CGRectGetMaxY(rect) * .8);
CGPoint cp2 = CGPointMake( (CGRectGetMaxX(rect) / 4) / 2 , CGRectGetMaxY(rect) * .8);

[aPath addQuadCurveToPoint:p2 controlPoint:cp2];

//close the path
[aPath closePath];

//set the line width
aPath.lineWidth = 2;

//set the stoke color
[[UIColor greenColor] setStroke];

//draw the path
[aPath stroke];
}


Related Topics



Leave a reply



Submit