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;
@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.