Home Prevent zooming/heading update stop in iOS MKMapView
Reply: 0

Prevent zooming/heading update stop in iOS MKMapView

PJ Slauta
1#
PJ Slauta Published in 2017-12-07 19:42:40Z

In iOS I have an MKMapView and CLLocationManager to update the heading and location. No matter what I do, I can't get the map view to stop zooming in tightly on the user's location. I have annotations on the map that I want visible at all times, and I want the heading to update as the user spins the device. This is working using mapView.setRegion, but after a bit, the map locks at the north and no longer rotates. Below is the CLLocationManager code I'm using:

func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
    if data != nil{
        setRegion(locationManager?.location?.coordinate.latitude)!, longitude: (locationManager?.location?.coordinate.longitude)!), data: data!)
    }
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if !regionSet && data != nil{
        setRegion(location: CLLocationCoordinate2D(latitude: (locationManager?.location?.coordinate.latitude)!, longitude: (locationManager?.location?.coordinate.longitude)!), data: data!)
        regionSet = true
    }
}

setRegion calculates the extents of the map to zoom on and sets the setRegion function appropriately.

Below is setRegion. I calculate the zoomWindowDegrees variable when I load in the annotations by finding the maximum lat/long for the annotations and the use that in the function.

private func setRegion(location:CLLocationCoordinate2D, towers:[Tower]){
        let center = location

        let coordinateSpan = MKCoordinateSpan(latitudeDelta: zoomWindowDegrees, longitudeDelta: zoomWindowDegrees)
        let region = MKCoordinateRegion(center: center, span: coordinateSpan)
        mapView.setRegion(region, animated: false)
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.331844 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO