Having trouble with mapkit usertrackingwithheading mode on iOS 6
Asked Answered
I

1

17

I think I may have discovered a bug in the mapkit API for iOS 6, but since I still consider myself a rookie I thought I'd check here to see if anyone can point out something I may be doing wrong.

I have an app that I've been working on for a few weeks with a mapview in it and utilizing the MKUserTrackingButton to toggle tracking modes. On iOS 5 it was working fine but since upgrading to 6 it has weird behavior. When you put the mapview into The tracking mode that follows user with heading, it does fine if you are relatively stationary, but when you start moving in a car it drops out of the track with heading mode every time back to regular tracking mode. After many frustrating hours trying to figure it out I decided to make a new simple app with the bare minimum mapview and tracking to see if it was just my coding or possible bug. The new app does the same thing. I'm posting all the code below. Hopefully some one can help tell me if I'm doing something wrong or not.

Here's the app delegate header

//  iTrackerAppDelegate.h
//  iTracker
//
//  Created by Victor Hudson on 9/22/12.
//  Copyright (c) 2012 Victor Hudson. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "TrackerViewController.h"

@interface iTrackerAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) IBOutlet UIWindow *window;

@end

Here's the app delegate implementation

    //
    //  iTrackerAppDelegate.m
    //  iTracker
    //
    //  Created by Victor Hudson on 9/22/12.
    //  Copyright (c) 2012 Victor Hudson. All rights reserved.
    //

    #import "iTrackerAppDelegate.h"

    @implementation iTrackerAppDelegate

    @synthesize window = _window;

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        TrackerViewController *trackerView = [[TrackerViewController alloc] init];

        UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:trackerView];

        [self.window setRootViewController:navController];

        [[self window] makeKeyAndVisible];
        return YES;
    }

// the other app delegate methods are all empty so i left them out for brevity

    @end

Here's my view controller. It has a nib with the worldView in it and a segmented switch for toggling map modes(plain, sat, and hybrid) TrackerViewController.h

//
//  TrackerViewController.h
//  iTracker
//
//  Created by Victor Hudson on 9/22/12.
//  Copyright (c) 2012 Victor Hudson. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface TrackerViewController : UIViewController

@property (strong, nonatomic) IBOutlet MKMapView *worldView;

- (IBAction)toggleMapView:(id)sender;

@end

TrackerViewController.m

//
//  TrackerViewController.m
//  iTracker
//
//  Created by Victor Hudson on 9/22/12.
//  Copyright (c) 2012 Victor Hudson. All rights reserved.
//

#import "TrackerViewController.h"

@interface TrackerViewController ()

@end

@implementation TrackerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    // navigation item
    [[self navigationItem] setTitle:@"iTracker"];

    MKUserTrackingBarButtonItem *trackingButton = [[MKUserTrackingBarButtonItem alloc] initWithMapView:self.worldView];
    [[self navigationItem] setRightBarButtonItem:trackingButton animated:YES];

    self.worldView.userTrackingMode = 1;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)toggleMapView:(id)sender {
    switch ([sender selectedSegmentIndex]) {
        case 0:
        {
            [self.worldView setMapType:MKMapTypeStandard];
        }break;
        case 1:
        {
            [self.worldView setMapType:MKMapTypeSatellite];
        }break;
        case 2:
        {
            [self.worldView setMapType:MKMapTypeHybrid];
        }break;
    }
}
@end

As I said before all seems to work fine but the tracking with heading mode when you are moving very fast. I am running on an iPhone 4, and Ive tried the app with and without ARC to the same results. I would be grateful if someone can point out any mistakes I'm making or if they want to build the project and can confirm it is a bug.

Thanks in advance for any assistance ;-)

Immanuel answered 22/9, 2012 at 18:24 Comment(5)
Almost 24 hours on a clearly explained question with source code and all. Nobody has anything on this? :(Immanuel
Could someone at least consider voting this up so it may get more eyes?Immanuel
Did you find a solution by now? I'm having the same problem :-(Uranic
I have not. I filed a bug report with apple and got a response that it was a duplicate. I must admit I haven't tried again in a few os updates so it's possible they have fixed it by now.Immanuel
They haven't fixed it.Harebell
P
1

I'm currently investigating a similar behaviour in my app when going from ios5 to ios6. There is a locationmanager created as a singleton as described in

cllocationmanager singleton

Furthermore in the mapview I'm using setusertrackingmode. In ios6 it jumps from MKUserTrackingModeFollowWithHeading to MKUserTrackingModeFollow back and forth. In ios5 it works fine with identical code. It may be that the two locationmanagers are in conflict with each other as pointed out in

conflict between two locationmanagers

Puga answered 30/9, 2012 at 20:46 Comment(4)
Your answer makes since to me, but I think it's not the source of my problem even though our apps are experiencing the same odd behaviors. My original app that brought this to my attention did have a locationmanager in the app delegate that I suppose could have conflicted with my mapView in the view controller, but the sample test project I detailed above has no locationManger to conflict with the mapView. It has only what I've listed above and nothing else. I really feel like its a bug or change in iOS 6. Interestingly though the iOS maps app still uses followWithHeading just fine.Immanuel
I think they must be using a different private api in the maps app. For what it's worth I have filed a bug report with apple. No response so far, but I'll post here when and if I get one.Immanuel
I just reproduced the odd behaviour (unwanted switching from MKUserTrackingModeFollowWithHeading to MKUserTrackingModeFollow) with a single location manager. It occurs only at "too" detailed zoom levels. Try setting the regionspan to a larger value.Puga
Ill try it out zoomed a little further out when I go out tomorrow. Even if that works, shouldn't apple still address this though? I'm not zooming in any tighter now than on iOS 5. Besides if your trying to use it in any sort of navigation being restricted to a wide zoom may not be very usefull to the user. Thoughts?Immanuel

© 2022 - 2024 — McMap. All rights reserved.