Как отключить автоматическое масштабирование при использовании userTrackingMode?

Я пытаюсь уменьшить масштаб карты, но она продолжает увеличиваться из-заэто установлено на. Есть ли способ предотвратить или написать свой собственный метод режима отслеживания?

Я пытался отключить отслеживание примерно на 20 секунд, но столкнулся с той же проблемой. Я также пытался просто использовать камеру, отправив ее в местоположение пользователя, но это тоже не сработало. Вот мой код:

      import SwiftUI
import Combine
import MapKit

struct MyMapView: UIViewRepresentable {
    @State var locationManager = CLLocationManager()
    @Binding var span: Double
    
    class Coordinator: NSObject, MKMapViewDelegate {
        var parent: MyMapView
        
        init(_ parent: MyMapView) {
            self.parent = parent
            super.init()
        }
    }
    
    func makeUIView(context: Context) -> MKMapView {
        setupManager()
        
        let mapView = MKMapView(frame: UIScreen.main.bounds)
        mapView.mapType = MKMapType.satellite
        mapView.showsUserLocation = true
        mapView.showsCompass = false
        mapView.isZoomEnabled = true
        
        mapView.delegate = context.coordinator
        
        // Version 1
        mapView.userTrackingMode = .follow
        
        /*
        // Version 2
        let camera1 = MKMapCamera(
            lookingAtCenter: mapView.centerCoordinate,
            fromEyeCoordinate: mapView.centerCoordinate,
            eyeAltitude: span)
        mapView.setCamera(camera1, animated: false)
        */
         
        return mapView
    }
    
    func updateUIView(_ uiView: MKMapView, context: Context) {
        
        // Version 1 -- zoom out of the map over the span variable
        uiView.setRegion(MKCoordinateRegion(center: uiView.centerCoordinate, latitudinalMeters: CLLocationDistance(span), longitudinalMeters: CLLocationDistance(span)), animated: false)
        
        // Deactivating the tracking and activating the tracking after 60sec and then disable it again.
        uiView.userTrackingMode = .none
        DispatchQueue.main.asyncAfter(deadline: .now() + 60.0) {
            uiView.userTrackingMode = .follow
        }
        uiView.userTrackingMode = .none

        /*
        // Version 2 -- Camera
        let camera2 = MKMapCamera(
            lookingAtCenter: uiView.centerCoordinate,
            fromEyeCoordinate: uiView.centerCoordinate,
            eyeAltitude: span)
        uiView.setCamera(camera2, animated: false)
        */
    }
    
    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }
    
    func setupManager() {
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestWhenInUseAuthorization()
        locationManager.requestAlwaysAuthorization()
    }
}

Есть ли решение моей проблемы?

0 ответов

Другие вопросы по тегам