1

I'm new to iOS programming. I am trying to draw one line between two points not more than one line. This is what I tried so far;

Result Map Record Moments

@property (nonatomic, strong) MKPolylineView *lineView;
@property (nonatomic, strong) MKPolyline *line;

Create a polyline all location ;

-(void)allLocationRoute {


CLLocationCoordinate2D coordinates[record.toMoments.count];

int i = 0;
for (MomentEntity *currentEntity in record.toMoments.allObjects) {

    coordinates[i].latitude = [currentEntity.latitude doubleValue];
    coordinates[i].longitude = [currentEntity.longitude doubleValue];
    i++;
}
MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coordinates count:record.toMoments.allObjects.count];
[self.mapView addOverlay:polyline];
line = polyline;

}

MapView:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay {

if ([overlay isKindOfClass:[MKPolyline class]]) {
    self.lineView = [[MKPolylineView alloc]initWithPolyline:(MKPolyline*)overlay] ;
    self.lineView.strokeColor = [[UIColor redColor] colorWithAlphaComponent:1];
    self.lineView.lineWidth = 1;
    return self.lineView;
}
return nil;
}

But as you can see from first picture red line makes zig-zag. Any help appreciated.

Emre YILMAZ
  • 152
  • 2
  • 10
  • 2
    hope it's help you [http://stackoverflow.com/questions/10598322/iphone-how-to-draw-line-between-two-points-on-mapkit](http://stackoverflow.com/questions/10598322/iphone-how-to-draw-line-between-two-points-on-mapkit) – Vvk Dec 02 '15 at 13:11

0 Answers0