I’m building a fitness application which tracks user’s movement using Core Location framework.
I’m saving the data using Core Data framework. Currently I have two entities; Workout and Location. Workout consists of these Location objects, which have latitude and longitude as their main attributes.
When I’m trying to create MKPolyLine from these Location objects it takes an awful lot of time on device.
- (void)createRouteLineAndAddOverLay
{
CLLocationCoordinate2D coordinateArray[[self.workout.route count]];
for (int i = 0; i < [self.workout.route count]; i++) {
CLLocationCoordinate2D coordinate;
coordinate.latitude = [[[self.workout.route objectAtIndex:i] latitude] doubleValue];
coordinate.longitude = [[[self.workout.route objectAtIndex:i] longitude] doubleValue];
coordinateArray[i] = coordinate;
}
self.routeLine = [MKPolyline polylineWithCoordinates:coordinateArray count:[self.workout.route count]];
[self.mapView addOverlay:self.routeLine];
[self setVisibleMapRect];
}
Could using of scalars make any performance improvement? Or should I try to filter out some of these locations points with some kind of algorithm when saving them?
The Trick here is to do the sorting on the database side.
This method took only 0.275954 seconds when workout had 1321 locations