Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import MapKit
- import CoreLocation
- class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
- @IBOutlet weak var mapView: MKMapView!
- var manager = CLLocationManager()
- override func viewDidLoad() {
- super.viewDidLoad()
- // add the some text to your plist entry: "Privacy - Location When In Use Usage Description"
- manager.requestWhenInUseAuthorization()
- }
- func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
- if status == CLAuthorizationStatus.authorizedWhenInUse || status == CLAuthorizationStatus.authorizedAlways {
- mapView.mapType = MKMapType.standard
- mapView.delegate = self
- mapView.showsTraffic = true
- mapView.showsUserLocation = true
- mapView.setUserTrackingMode(MKUserTrackingMode.followWithHeading, animated: true)
- }
- }
- }
Add Comment
Please, Sign In to add comment