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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With