4

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?

eric.mitchell
  • 8,817
  • 12
  • 54
  • 92
  • So is it when a new segment gets added or hen the app returns from the background? Maybe a combination of the two? – Mark Adams Dec 08 '11 at 00:13
  • It happens when new segments are added after returning from the background. Would it have something to do with the fact that the segments are added from a background thread? – eric.mitchell Dec 08 '11 at 00:19

2 Answers2

1

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.

Mark Adams
  • 30,776
  • 11
  • 77
  • 77
  • Yes, I think that might just be the problem; I have had other problems with CLLocationManager and threading when the app enters the background. – eric.mitchell Dec 08 '11 at 00:49
  • Yes, I do think that this solved the problem. I'll have to do a few more tests to be sure of it though. – eric.mitchell Dec 08 '11 at 00:54
0

I think your best bet is to try to get the flash over with before you show the map to the user.

Try one of the following:

[mapView setNeedsDisplay];

or

if ([[mapView overlays] count] > 0){
    [[[mapView overlays] lastObject] setNeedsDisplay];
}

Put these in either your "viewWillAppear" method, or the "applicationWillEnterForeground" method in AppDelegate.m.

llama591
  • 453
  • 5
  • 15