How to approach the vision of its location, and make it follow along a path?

Asked

Viewed 75 times

0

please, I am new in the area and am creating an app that will count the distance, speed, calories spent and time by the user during a run/walk.

the simulator is finding the location, but the screen does not follow the walk, besides the view from above (commonly called "span"), stay extremely far by default, and need it already start approximate.

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

Thank you all very much!

// Defining the 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 locates the current location @Ibaction works to 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)            
    }()

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 don’t need to create a Timer to update the location, the "didUpdateLocations" method already automatically does this for you.

0

To bring the map closer to the location, change the span, as you said yourself... The lower the span value, the closer the view is.

To "track" the offset, I suggest that in the locationManager(_ manager: Cllocationmanager, didUpdateLocations Locations: [Cllocation]) function you enter the location on the map. So whenever the location changes, the user will be centralized again.

To center, you can use:

Let currentSpan = Mkcoordinatespanmake(defaultSpan, defaultSpan)
Let Region : Mkcoordinateregion = Mkcoordinateregionmake(desiredLocation.coordinate, currentSpan) map.setRegion(Region, Animated: true)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.