Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 13.2 removing overlay from MapKit causing map to flicker

I am using mapKit in my app and I have several functions that render graphics using layers of overlays. Now, with iOS 13.2 update, when I move the map (with any method) functions that remove a single overlay and redraw the overlay as the map moves - cause all the graphics in the map to flicker - as if they are all being redrawn. One of the methods for moving the map is 'didUpdateLocations' by the locationManager.

I can't post code, because the code is split up over so many sub functions all called in different combinations. But I have tested many ways to verify that the graphics flicker just from the single action of adding or removing an overlay. And I have evaluated the overlay being added or removed to verify that it is only a single small graphic (MKPolyline) - not the set of graphics/overlays on the map.

So basically, there seems to be something wrong with the addOverlay function - redrawing all overlays.., or something like this...

Anyone else experiencing this issue with iOS13.2?

like image 693
Aroniousness Avatar asked Nov 02 '19 19:11

Aroniousness


1 Answers

A similar thing is happening to me. I have an app that hasn't changed in several months, but when I upgraded to iOS 13.2, it started misbehaving. The app has a mapView that renders MKTileOverlays. A 2x2 grid of tiles that surrounds the center blue dot is blinking continuously at a rate of once per second, at all zoom levels. I was able to capture the screen (on an iPhone) right when it blinked, and I can see it's showing a number of tiles at higher zoom levels.

In the picture below, the map is at zoom level 14. I outlined the 2x2 blinking tiles in green. When it blinks, several tiles at zoom level 16 (outlined in orange) and zoom level 17 (outlined in purple) appear.

The higher zoom-level tiles only appear if I previously zoomed up to that level in those areas. Otherwise, the 2x2 blinking grid is empty.

enter image description here

Update:

Here is the reply I received from Apple Developer Technical Support on 12/5/2019...

What you’re seeing is a known bug in MapKit. I wanted to pass along some additional information to help reduce how often you may see this in your real app. A common pattern that some apps use in the MKMapView usage is to do frequent updates to their overlays, such as removing all overlays at once, and then adding some subset (or all) of them back. In particular, if this is done to the hot code paths for user driven events, such as pinching and zooming the map, the blinking tile behavior is exacerbated.

In the case of the sample [provided by P. Stern], this is the location manager’s location update, which can be called at 60 Hertz in some circumstances. You can do something like a distance comparison and only update the polyline if there’s a significant enough change in the coordinate since the last time you replaced the polyline to be meaningful to the user for your trail use case. Applying this to your real app, please audit the points where you add and remove overlays, and try to reduce the number of times those methods get called. This won’t eliminate the tile blinking problem, but may reduce its frequency as a way to mitigate the effects of our issue.

When looking at your overlays, also consider why you need to add and remove overlays from the map, and if there are opportunities to do so in bulk, but rarely. Another common pattern I see often is trying to keep track of the overlays to keep memory usage down, and continually updating the overlays added to the map to reflect only those relevant to the user’s location or visible map rectangle. However, the MKOverlay objects themselves are usually not large, because they are only a coordinate and a bit of data, so the memory saved by these techniques is often in the kilobyte to low megabyte range, which isn’t much improvement when an app with a map needs 100 MB just for the map, let alone the rest of the app’s data and view controllers.

Final Update:

The issue seems to have been resolved by Apple. I am using iOS 13.7 (Xcode 12) and the blinking is no longer occurring. It may have been fixed in iOS 13.4 as Zifigo noted.

like image 98
P. Stern Avatar answered Sep 24 '22 17:09

P. Stern