How to approach the view of your location, and make it follow during a journey?

0

Please, I'm new to the area and I'm creating an app that will tell the distance, speed, calories spent, and user time during a race / walk.

The simulator is finding the location, but the screen does not follow the walk, besides the view from above (commonly called "span"), get extremely far by default, and needs to start approx. >

Can you help me? Here are the parts that I deem important for a better understanding of my doubt:

Thank you very much!

// Defining location accuracy

    self.gerenciadorGPS.desiredAccuracy = kCLLocationAccuracyBest

    segundos = 0.0
    distancia = 0.0
    locations.removeAll(keepingCapacity: false)
    timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(self.atualizaSegundo(timer:)), userInfo: nil, repeats: true)
    startLocationUpdates()

// Button that finds the current location @IBAction func locate (_ sender: UIButton) {

    // Verificando a autorização de status

    if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedWhenInUse && CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedAlways) {

        self.gerenciadorGPS.requestWhenInUseAuthorization()
    }
    self.mapa.showsUserLocation = true
    self.gerenciadorGPS.delegate = self
    self.gerenciadorGPS.startUpdatingLocation()

var locationManager: CLLocationManager = {
        var _locationManager = CLLocationManager()
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest
        _locationManager.activityType = .fitness

        // Movement threshold for new events
        _locationManager.distanceFilter = 10.0
        return _locationManager

        let localizacao = _locationManager
        let span = MKCoordinateSpanMake(0.04, 0.04)
        let regiao = MKCoordinateRegionMake(_locationManager as! CLLocationCoordinate2D, span)            
    }()
    
asked by anonymous 10.04.2017 / 16:57

2 answers

0

Hello, try to perform the test on a device, I believe that with the simulator you will not be able to perform these tests.

You do not need to create a Timer to be able to update the location, the "didUpdateLocations" method already does this automatically for you.

    
10.04.2017 / 20:21
0

To approximate the map of the location, change the span, as you yourself said ... The lower the span value, the closer the area is displayed.

To "track" the offset, I suggest you center the location on the map in the locationManager (_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) function. So, whenever the location changes, the user will be centralized again.

To centralize, you can use:

let currentSpan = MKCoordinateSpanMake (defaultSpan, defaultSpan)
let region: MKCoordinateRegion = MKCoordinateRegionMake (desiredLocation.coordinate, currentSpan) map.setRegion (region, animated: true)

    
13.04.2017 / 21:09