Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 871
Scott Avatar asked Jun 29 '14 22:06

Scott


People also ask

What is .map SwiftUI?

Overview. A map view displays a region. Use this native SwiftUI view to optionally configure user-allowed interactions, display the user's location, and track a location.


1 Answers

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.

like image 159
Paulw11 Avatar answered Nov 15 '22 05:11

Paulw11