In viewDidLoad
, the code calls addOverlay
with self.routeLine
which I assume is initially set to the previously-saved coordinates.
The map view adds the MKPoyline
that routeLine
points to into its internal list of overlays and draws the overlay.
Then, in the "function that handles each new coordinate", self.routeLine
is changed to point to a new MKPolyline
.
The reason the overlay view is not updated by the map is because the map view is still using the original MKPolyline
that was passed to it when addOverlay
was called.
Since MKPolyline
itself is not mutable (it does not allow one to change the list of points/coordinates after creation), there are two main options:
Remove the existing overlay and add a new one with the updated coordinates. This is the simplest option. After setting
self.routeLine
to a newMKPolyline
, do the following (for example):[self.mapView removeOverlays:mapView.overlays]; self.routeLineView = nil; [self.mapView addOverlay:self.routeLine];
The main drawback to this simple approach is that the overlay will seem to flicker if the updates are done frequently or if the overlay is large or complex.
The alternative is to create a custom overlay and overlay view that are mutable and enabling you to dynamically refresh the overlay more quickly and smoothly.
Fortunately, Apple has provided a sample app called Breadcrumb which does exactly that.