Reputation: 13
Currently the user location is logged each time he visits the home screen. It needs to also update when the user is on the move so that the location stays current.
Here I set the location upon login
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let databaseRef = Database.database().reference()
let uid = Auth.auth().currentUser!.uid
guard let locValue: CLLocationCoordinate2D = manager.location?.coordinate else { return }
print("locations = \(locValue.latitude) \(locValue.longitude)")
latestLocation = ["latitude" : locValue.latitude, "longitude" : locValue.longitude]
let lat = locValue.latitude
let lon = locValue.longitude
dict = CLLocation(latitude: lat, longitude: lon)
print("dict", dict)
if let locationDictionary = latestLocation {
databaseRef.child("people").child(uid).child("Coordinates").setValue(locationDictionary)
}
}
Now I just nee it to always setValue when user moves materially.
Upvotes: 0
Views: 36
Reputation: 105
You can look into startMonitoringSignificantLocationChanges()
method and don't for get to call startUpdatingLocation
Upvotes: 1