MKOverlay Update

In my application, I use MKPolyline to track the user path. Sometimes (and not all the time, which I don’t understand), when a new new segment is added to the map, the entire line blinks. This is sometimes not the case. This is the code used to add 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]; 

Did I miss something?

Edit: This usually happens when the application returns from the background. I'm not quite sure why, though, because I only add the overlay without changing the entire mapView.overlays array .... right?

+4
source share
2 answers

This may not be related, but Apple states in the "Map Overlay Management" in the Location Programming Guide ...

Since the map view is an interface element, any changes to the overlays array must be synchronized and executed on the main application thread.

+1
source

I think it’s best to try to get a flash before showing the card to the user.

Try one of the following:

 [mapView setNeedsDisplay]; 

or

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

Put them in your viewWillAppear method or applicationWillEnterForeground method in AppDelegate.m.

0
source

All Articles