So I am trying to do 3 things.
- Have a map which shows my location.
- Map should be slightly slanted to give a 3d feel; same like when we scroll up and down with 2 fingers on apple map.
- Use compass to rotate the map.
I have enabled userTrackingMode on the map and the map rotates with compass but if I set a MKMapCamera on the map the compass won't work.
Here is my code.
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")
}
What am I doing wrong here?
You have to update the heading of the camera with the compass. Here's something that I'm currently using: