I am writing an iOS 5 app which tracks a user's location in real-time, plotting their course on a MKMapView
. Whenever a GPS reading is taken I would like a polyline to be drawn between the current and old locations, eventually forming a track (or breadcrumb) of where the user has travelled.
I am comfortable with using MKPolyline
and MKPolylineView
to draw a track, assuming that I have all the CLLocationCoordinate2D
coordinates in advance, using code similar to below:
MKPolyline *route = [MKPolyline polylineWithCoordinates:coordinates count:[self.coordinateArray count]];
[mapView addOverlay:route];
However, since I am only getting the CLLocationCoordinate2D
coordinates in real-time (as the locationManager:didUpdateToLocation:fromLocation:
delegate method is called) I am unsure of the best way to draw the new polylines.
Can I extend the existing lines (i.e. adding to the C-based coordinates
array - not having much C experience I am unsure how to do this) or do I need to create a new polyline between the next two coordinates (although I have heard that having too many individual polylines on the map can impact performance and memory usage...)?
Thanks in advance.