swift - Displaying the speed the device is travelling at using CLLocationSpeed -


i able display speed device travelling @ in simple label.

i have found on apples website:

var speed: cllocationspeed { }

source

the code above puts speed in m/s , can therefore convert miles per hour etc.

how can use code display speed?

i know can done because snapchat has filter.

i found here on @leo

swift: exception while trying print cllocationspeed "unexpectedly found nil while unwrapping optional value" :

import uikit import corelocation class viewcontroller: uiviewcontroller, cllocationmanagerdelegate { let locationmanager = cllocationmanager()  override func viewdidload() {   super.viewdidload()     // additional setup after loading view, typically nib.     locationmanager.delegate = self     if nsstring(string:uidevice.currentdevice().systemversion).doublevalue > 8 {         locationmanager.requestalwaysauthorization()     }     locationmanager.desiredaccuracy=kcllocationaccuracybest   }    func locationmanager(manager: cllocationmanager!, didupdatelocations locations: [anyobject]!) {     var speed: cllocationspeed = cllocationspeed()     speed = locationmanager.location.speed     println(speed);   }    func locationmanager(manager: cllocationmanager!, didchangeauthorizationstatus status: clauthorizationstatus) {     if status != clauthorizationstatus.denied{         locationmanager.startupdatinglocation()     }   } } 

then in viewdidload, or wherever, can make label:

      mylabel = uilabel()         mylabel.text        = "myspeed: \(speed)"          self.addchild(mylabel) 

just make sure 'speed' variable in scope wherever trying use (i didn't demonstrate).

it compiled me. hope helps. haven't used before, search function i'm confident can learn here :d


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -