Search code examples
iosobjective-cios7mkmapviewmkusertrackingmode

MKMapView in iOS 7


I have a problem with MKMapView in iOS7, I have been using it with iOS5 and worked flawless (at least what Im trying to do).

Well my problem is that .userTrackingMode won't work in iOS7. Been searching for an answer but haven't found any.

I want to show user location, it work fine with .showsUserLocation. But when I want to track it its like it just ignores it. Anyone have a fix?

This is how I wrote it in iOS 5:

mMapView.showsUserLocation = YES;

mMapView.userTrackingMode = YES;

mMapView.userInteractionEnabled = NO;

And what I know there wasn't any changes with the code in the upgrade.

EDIT:

Don't know why but I used [self.mapView setUserTrackingMode:MKUserTrackingModeFollow animated:YES]; inside a method that change a label every time that the location change. Then its working.

Don't know why it's not working when I declare it in viewDidLoad... ?


Solution

  • Welp, in Apple's documentation for MKMapView, ".userTrackingMode" is not a BOOL but instead it's an "enum" (Integer) property:

    typedef enum : NSInteger {
       MKUserTrackingModeNone = 0,
       MKUserTrackingModeFollow,
       MKUserTrackingModeFollowWithHeading,
    } MKUserTrackingMode;
    

    Maybe you're setting it wrongly could be part of the problem?

    Also, the best way to set it is via this API:

    - (void)setUserTrackingMode:(MKUserTrackingMode)mode animated:(BOOL)animated (I've linked the Apple documentation for you). There's a useful "animated" argument there.