2016-04-13 13 views
1

3つのことをやろうとしています。MKMapCameraを使用するとコンパスはMKMapViewで動作しません

  1. 私の所在地を示す地図があります。
  2. マップは、3Dの感触を与えるために少し傾いている必要があります。アップルマップ上で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") 

     } 

私はここで間違っていますか?

+0

誰でも助けてくれますか? –

答えて

1

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

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) { 
     self.mapView.camera.heading = newHeading.trueHeading 
} 
関連する問題