swift - CoreLocation User Speed -
i trying current user's device movement speed. here's code:
import uikit import foundation import corelocation class viewcontroller: uiviewcontroller, cllocationmanagerdelegate { let manager = cllocationmanager() var currentspeed = 0.0 override func viewdidload() { super.viewdidload() manager.requestwheninuseauthorization() manager.delegate = self manager.desiredaccuracy = kcllocationaccuracyhundredmeters manager.startupdatinglocation() } func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) { print(manager.location?.speed) } func locationmanager(manager: cllocationmanager, didfailwitherror error: nserror) { print("error: \(error.localizeddescription)") } the issue prints "optional(-1,0)"
thanks in advance.
core location give negative value speed if device isn't moving, or moving enough math doesn't make sense.
Comments
Post a Comment