Rotate Map

Hi

I am working on a walk tracking app adn would like to rotate the map so that when i am walking the map rotates so that my heading is always pointing to the top of the screen. I sort of have it working but the map keeps resetting back to normal rotation.


private func startLocationUpdates() {

// our delegate

locationManager.delegate = self

//sets the orintation of the phone

locationManager.headingOrientation = .portrait

// our type filter

locationManager.activityType = .fitness //can be automotive

locationManager.distanceFilter = 10

locationManager.startUpdatingLocation()

// check to see if we can get a heading update

if (CLLocationManager.headingAvailable()) {

// 5 degree change before we update

locationManager.headingFilter = 5

locationManager.startUpdatingHeading()

}

}


I use the locationmanagers updateheading then set teh camera heading to that


mapView.camera.heading = newHeading.trueHeading

mapView.setCamera(mapView.camera, animated: true)

Is it your code that is doing the "reset"? i.e. that setCamera call in your update heading function?


If so, you might need to take a look at when that method is being called. Maybe you'll need to do your own filtering. Only change the heading if the last few location updates have had a consistent nonzero speed and/or heading for example.


When does the heading "reset"? When you stop moving, start moving, change phone orientation, ???

Rotate Map
 
 
Q