ggirao ggirao - 1 month ago 9
Swift Question

return a tag when startMonitoringSignificantLocationChanges()

I'm developing an ios (swift) app that sends positions with CLLocationManager startUpdatingLocation to a server trough an API. For battery and data economy I would like to not send this data to API when the device is stopped (or at some near location). My ideia is to call the API only when startMonitoringSignificantLocationChanges(). Is there a way to return a bool value? TY

Answer

I found it myself.

I got the last 2 elements of the coordinates and then:

/My location
        let myLocation = CLLocation(latitude: firstArrayLatitude, longitude: firstArrayLongitude)

        //My buddy's location
        let myBuddysLocation = CLLocation(latitude: lastArrayLatitude, longitude: lastArrayLongitude)

        //Measuring my distance to my buddy's (in km)
        let distance = myLocation.distanceFromLocation(myBuddysLocation) / 1000