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.

https://developer.apple.com/library/ios/documentation/corelocation/reference/cllocation_class/#//apple_ref/occ/instp/cllocation/speed


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -