import UIKit
import MapKit
import CoreLocationUI

class ViewController: UIViewController, MKMapViewDelegate {
   @IBOutlet weak var mapView: MKMapView!
   @IBOutlet weak var stackView: UIStackView!

   override func viewDidLoad() {
      super.viewDidLoad()
      let button = CLLocationButton()
      button.cornerRadius = 10
      button.label = .currentLocation
      stackView.addArrangedSubview(button)

      mapView.mapType = .standard
      mapView.isRotateEnabled = false
      mapView.showsUserLocation = true
      
      mapView.delegate = self
   }
   func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
      let location = mapView.userLocation
      let region = MKCoordinateRegion(center: location.coordinate, latitudinalMeters: 1000, longitudinalMeters: 1000)
      mapView.setRegion(region, animated: true)
   }
}