Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Draw a route between two annotation point on MKMapView

    • 0
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 560
    Comment on it

    The following lines of code helped me to draw a route between two Annotation point in MKMapView


    Hope this will help you in your coding

    CSRouteAnnotation* routeAnnotation = (CSRouteAnnotation*)self.routeView.annotation;
    
        // only draw our lines if we're not int he moddie of a transition and we 
        // acutally have some points to draw. 
        if(!self.hidden && nil != routeAnnotation.points && routeAnnotation.points.count > 0)
        {
            CGContextRef context = UIGraphicsGetCurrentContext(); 
    
            if(nil == routeAnnotation.lineColor)
                routeAnnotation.lineColor = [UIColor blueColor]; // setting the property instead of the member variable will automatically reatin it.
    
            CGContextSetStrokeColorWithColor(context, routeAnnotation.lineColor.CGColor);
            CGContextSetRGBFillColor(context, 0.0, 0.0, 1.0, 1.0);
    
            // Draw them with a 2.0 stroke width so they are a bit more visible.
            CGContextSetLineWidth(context, 2.0);
    
            for(int idx = 0; idx < routeAnnotation.points.count; idx++)
            {
                CLLocation* location = [routeAnnotation.points objectAtIndex:idx];
                CGPoint point = [self.routeView.mapView convertCoordinate:location.coordinate toPointToView:self];
    
    
    
                if(idx == 0)
                {
                    // move to the first point
                    CGContextMoveToPoint(context, point.x, point.y);
                }
                else
                {
                    CGContextAddLineToPoint(context, point.x, point.y);
                }
            }
    
            CGContextStrokePath(context);
    

    Happy Coding

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: