Any Workaround to MKUserTrackingModeFollowWithHeading Bug in iOS6?

779 views Asked by At

I'm desperately looking for a workaround to the well documented bug in MapKit in iOS6 that makes MKUserTrackingModeFollowWithHeading effectively unusable at higher magnifications:

There is a very simple example project [here].(https://dl.dropboxusercontent.com/u/316978/MapKitBug.zip)

Steps to reproduce:

  1. Tap the MKUserTrackingModeButton to zoom in to your location.
  2. Tap to zoom in closer 2 or 3 times.
  3. Tap MKUserTrackingModeButton to select MKUserTrackingModeFollowWithHeading

Issues:

This mode will not 'stick' and almost always exits after a matter of seconds (1-20). The Blue 'Your Location' Annotation 'vibrates' and seems to move slightly from its central position whilst it's in MKUserTrackingModeFollowWithHeading.

Note that this is increasingly a problem as you zoom in. At the default magnification (which you are taken to when first tapping the MKUserTrackingModeButton Button, it is not so much of a problem.

An obvious workaround would be to limit zoom level, but unfortunately I need full zoom in my application.

2

There are 2 answers

3
BigDan On BEST ANSWER

I , too, got frustrated with this extremely annoying bug.

I have a deadline just around the corner, so I can't spend a lot of time trying to implement a workaround.

I had managed to get it to stay in MKUserTrackingModeFollowWithHeading at max zoom, but the User Location annotation "pin" still jittered around quite heavily, and in some edge cases, it was still canceling back into MKUserTrackingModeFollow.

What I did, initially, was to force a correction using BOOL flags in the regionDidChangeAnimated: delegate method, like so:

    - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated {

        NSLog(@"regionWillChangeAnimated:");

    }

    - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {

        NSLog(@"regionDidChangeAnimated:");

        [self forceCorrectUserTrackingMode];

    }

    - (void)forceCorrectUserTrackingMode {

        if (shouldFollowWithHeading == YES && ([mapView userTrackingMode] !=         MKUserTrackingModeFollowWithHeading) ) {

          NSLog(@"FORCE shouldFollowWithHeading! - setUserTrackingMode:MKUserTrackingModeFollowWithHeading");
          [self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading animated:YES];

        } else if (shouldFollowWithHeading == NO && ([mapView userTrackingMode] != MKUserTrackingModeNone) ) {

          NSLog(@"FORCE should NOT FollowWithHeading - setUserTrackingMode:MKUserTrackingModeNone");
          [self.mapView setUserTrackingMode:MKUserTrackingModeNone animated:YES];

        }

    }

This actually got me pretty close, but it wasn't reliable enough, and like I said, I had to think about prioritizing other features for my deadline, so this is what I ended up doing:

  1. First, I grabbed this code for a zoom category on MKMapKit: http://troybrant.net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/

  2. Next, I included this method that a visitor provided in that blog's comments:

    - (int) getZoomLevel {
    
       return 21 – round(log2(mapView.region.span.longitudeDelta * MERCATOR_RADIUS * M_PI / (180.0 * mapView.bounds.size.width)));
    
    }
    
  3. Finally, a little trial and error testing the zoom levels vs. the occurrence of the bug led me to the following "workaround":

    CLLocationCoordinate2D userLocation_CenterCoordinate = CLLocationCoordinate2DMake([locationManager location].coordinate.latitude, [locationManager location].coordinate.longitude);
    
    int currentZoomLevel = [MKMapView getZoomLevelForMapView:mapView];
    
    int newZoomLevel = 17;
    
    if (currentZoomLevel > 17) {
    
        NSLog(@"Adjusting mapView's zoomLevel from [%d] to [%d], also centering on user's location", currentZoomLevel, newZoomLevel);
        [mapView setCenterCoordinate:userLocation_CenterCoordinate zoomLevel:newZoomLevel animated:NO];
    
    } else {
    
        NSLog(@"Centering on user's location, not adjusting zoom.");
        [mapView setCenterCoordinate:userLocation_CenterCoordinate animated:NO];
    
    }
    
0
Undistraction On

Opened a TSI, and Apple confirmed that there is no workaround. I wonder if they'll have fixed it in 7 …