1

だから私は3つのことをしようとしています。

  1. 私の場所を示す地図を持っています。
  2. 3D 感を出すために、マップを少し傾ける必要があります。Apple マップを 2 本の指で上下にスクロールするのと同じです。
  3. コンパスを使って地図を回転させます。

マップで userTrackingMode を有効にすると、マップはコンパスで回転しますが、マップに MKMapCamera を設定するとコンパスが機能しません。

これが私のコードです。

    override func viewDidLoad() {
            super.viewDidLoad()
            // Do any additional setup after loading the view, typically from a nib.
            locationManager.desiredAccuracy = kCLLocationAccuracyBest
            locationManager.delegate = self
            locationManager.requestWhenInUseAuthorization()
            mapView.setUserTrackingMode(.FollowWithHeading, animated: true)
            locationManager.startUpdatingLocation()

        }


func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {


            let userCordinate = CLLocationCoordinate2D(latitude: newLocation.coordinate.latitude, longitude: newLocation.coordinate.longitude)

            let eyeCordinate = CLLocationCoordinate2D(latitude: newLocation.coordinate.latitude - 0.021078, longitude: newLocation.coordinate.longitude - 0.04078 )



            let mapCamera = MKMapCamera(lookingAtCenterCoordinate: userCordinate, fromEyeCoordinate: eyeCordinate, eyeAltitude: 1400)

            mapView.setCamera(mapCamera, animated: true)
            print("Camera set")

        }

ここで何が間違っていますか?

4

1 に答える 1

1

コンパスでカメラの向きを更新する必要があります。ここに私が現在使用しているものがあります:

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
        self.mapView.camera.heading = newHeading.trueHeading
}
于 2017-01-06T04:18:12.073 に答える