Search code examples
iosmkmapviewcllocationmanagermkoverlay

MKOverlay update flashing


In my app, I use an MKPolyline to track the user's path. Sometimes (and not all the time, which I don't understand), when a new line segment gets added to the map, the entire line flashes. Sometimes it doesn't. This is the code being used to add the lines:

CLLocationCoordinate2D coords[2];

coords[0] = CLLocationCoordinate2DMake(newLocation.coordinate.latitude, newLocation.coordinate.longitude);

coords[1] = CLLocationCoordinate2DMake(oldLocation.coordinate.latitude, oldLocation.coordinate.longitude);

MKPolyline* line = [MKPolyline polylineWithCoordinates:coords count:2];

[mapView addOverlay:line];

Am I missing something?

Edit: This usually happens upon the app's return from being sent to the background. I'm not exactly sure why, though, because I am only adding an overlay, not modifying the entire mapView.overlays array. ...right?


Solution

  • This may not be related, but Apple does state in the Managing the Map's Overlay Objects section of the Location Awareness Programming Guide...

    Because the map view is an interface item, any modifications to the overlays array should be synchronized and performed on the application’s main thread.