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 { }
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
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
Post a Comment