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...
What could be wrong?
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?