Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having trouble with mapkit usertrackingwithheading mode on iOS 6

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 ;-)

like image 252
vichudson1 Avatar asked Sep 22 '12 18:09

vichudson1


1 Answers

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

like image 81
Heavy Avatar answered Nov 04 '22 00:11

Heavy