MKPolyline getting drawn from 0 degrees lat and long instead of one coordinate to other

I'm trying to draw an MKPolyline for the route taken by the user while walking. I pass a C array of coordinates and instead of seeing a polyline drawn from one coordinate to another, I see a many polylines from 0 degree latitude and 0 degree longitude to each coordinate.

Here is the code...

Code Block
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations;
{
    CLLocationCoordinate2D coordinates[locations.count];
    int index=0;
    for (CLLocation *location in locations)
    {
        [self centerMapWithCoordinates:location.coordinate];
        if (location.horizontalAccuracy>0)
        {
    MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
            point.coordinate = location.coordinate;
            point.title = [NSString stringWithFormat:@"%0.2f Kmph",(location.speed*3600/1000)];
            [self centerMapWithCoordinates:location.coordinate];
            [mapView addAnnotation:point];
            CLLocationCoordinate2D coordinate = location.coordinate;
            coordinates[index] = coordinate;
            index++;
        }
    }
    MKPolyline *polyline = [MKPolyline polylineWithCoordinates:coordinates count:index+1];
    [mapView addOverlay:polyline];
}


Code Block
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay;
{
    if ([overlay isKindOfClass:[MKPolyline class]])
    {
        MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:(MKPolyline *)overlay];
        renderer.strokeColor = [[UIColor orangeColor] colorWithAlphaComponent:0.7];
        renderer.lineWidth   = 3;
        return renderer;
    }
    return nil;
}

What could be wrong?

I couldn't get the answer to this even on Quora. I opened a support instance with apple and turns out I was incrementing the index that would set the size of the C array to by one more than required which resulted into polylines being drawn from co-ordinates (0.0, 0.0).
MKPolyline getting drawn from 0 degrees lat and long instead of one coordinate to other
 
 
Q