ios – Tracking location using Core Location


I’m trying to measure the distance a user travels with a simple iOS app. I’m new to Swift and I’m having some trouble figuring out how to use this Core Location distance method:

func distance(from location: CLLocation) -> CLLocationDistance

I can get the location data from a class I have setup with a variable called “payload”, and I can display the location data on the screen:

Text("Data received: \(locationDataManager.payload.description)")

Which displays:

Data received: [<+37.33165577,-122.03033803> +/- 10.00m (speed 2.03 mps / course 109.38) @ 12/24/23, 11:28:11 AM Central Standard Time]

I read this question and tried using one of the answers there, but I’m not sure how to get the source and destination data from what I have without pulling out latitude and longitude. Is that even necessary?

    func distanceBetweenTwoLocations(source:CLLocation,destination:CLLocation) -> Double{
        var distanceMeters = source.distance(from: destination)
        var distanceKM = distanceMeters / 1000
        return distanceKM
    }

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img