MapKit zoom to user current location

后端 未结 8 599
慢半拍i
慢半拍i 2021-02-01 17:59

I am trying to simply show user\'s location on the map, but I need to when app launches, the map should zoom to current location ,but I don\'t know why map doesn\'t zoom at all

8条回答
  •  春和景丽
    2021-02-01 18:37

    Try with MKMapViewDelegate func:

    var isInitiallyZoomedToUserLocation: Bool = false 
    
    func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
        if !isInitiallyZoomedToUserLocation {
           isInitiallyZoomedToUserLocation = true
           mapView.showAnnotations([userLocation], animated: true)
        }
    }
    

提交回复
热议问题