Scott
Scott

Reputation: 1342

What's the correct way to zoom in on a users location using swift with xcode

I have a map that I'm trying to use to zoom in on a users location and I can seem to get setUserTrackingMode to work correctly. I have showsUserLocation working fine but I can't get it to zoom in. I'm using xCode 6 with iOS 8 and swift. Here's how I'm trying to call the method:

@IBOutlet var mapView : MKMapView
override func viewDidLoad() {
    super.viewDidLoad()
    self.mapView.showsUserLocation = true
    self.mapView.delegate = self;
    self.mapView.setUserTrackingMode(MKUserTrackingModeFollow, animated: true);

I'm getting an error for self.mapView.setUserTrackingMode(MKUserTrackingModeFollow, animated: true);

The error says, "Use of unresolved identifier 'MKUserTrackingModeFollow'"

How can I get it to zoom in on the users location?

Upvotes: 5

Views: 4023

Answers (1)

Paulw11
Paulw11

Reputation: 115104

From the pre-release documentation the swift tracking modes are:

enum MKUserTrackingMode : Int {
    case None
    case Follow
    case FollowWithHeading
}

You should use -

self.mapView.setUserTrackingMode(MKUserTrackingMode.Follow, animated: true);

In Swift, as enums are treated as a type, "Follow" is interpreted within the scope of an MKUserTrackingMode enum.

Upvotes: 8

Related Questions