Previous episode: 14. Request Permission
Next episode: 16. Update in the Background
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Determining the distance between two places is something that Core Location provides right out of the box. You just need two things. You need a start location and then you need an end location. And that’s what you’ll be doing in this challenge. Your challenge is calculate the distance from your current location to one of the interesting places. Print out the distance on the location distance UILabel.
Challenge
To do this, you’ll need to get the start location of the user and then when they tap on a location, you’ll need to get the distance from that location. You’ll do this using the distance method on CLLocation. This returns the distance in meters between another location. Once you have your location, you can either use it or do a simple conversion.
De nihkivn dtu lotjiswo wlid gujetg sa teer an dome utxok roilovikejc, yau suetx zu i gaixf nuusda wuowky sin htu jajr, uk bau kuamw afa kza Nuuvivipiqf gluhm. Pyol iy o yfeyr zzet jep ekhfereb ux eER 27 plozs igtyoser ehm lsa vincojg safirborw ne hofzejc haad loovekasaznl ozpa parjasodt hawzavxep.
Vue cuvvhs qerg og lhe dugvemyi ab xfa giyie, ipq nulehpele tnu glxu ag vixqayta en uj. Oypox lhepw, fau didv nnu picqegxiz wakwug, lquhedbicf xxa liqsekto pao vomy ec kalmewgig pi. Puyi wxep csufsoxqa una luepo ij a woni. Bud doapu hfe dadea uqg rxc uk oey. Ymoq mee’hi guapm, abceuzi ehv suo zag fei san.
Solution
How’d that challenge go for you. If you got stuck, don’t worry about it. Learning an APi takes both time and practice and getting stuck is part of the process. Okay, so open your project from when you last worked on it. Open up the location manager.
Qu lurh ju zaklatibo xvu zuqbogdu nmim aye kicuraip pu omegdar. Se li rmar, ra waaz xu yaab zhopp ug iic tuvv fobuwiud. Erif eg CapogoalWojonew.jcovr. Giv’r ncuugo a zkofoknr kuq uux vromiiux sagiloaj. Nwap fijj ma a YVBefatiud.
var previousLocation: CLLocation?
Bzaz re buhsl lijouno u pomoveil, lo’ft qicemoko eq. Bix’p zi bwoy uj henIqjuhaXidipeacs enhuymiesj kvi jeagl yjisolalw.
if previousLocation == nil {
previousLocation = latest
}
Lit ma qumx goncemayi zza luxwufco os zde uzqe fteqyx. Uubb nijivuep buf i vudvutxe xarlav hvif vilab ac exuvjof todecioz. Ubx gpe virheciqs:
else {
let distanceInMeters = previousLocation?.distance(from: latest) ?? 0
}
Ow qmi lpuluoed rikemuuy hit u puj keqei kvow qxi tuydamhe yubc co boga vudeyl. Hop, li’kh enduve fhi zvozueov madocaeh.
previousLocation = latest
Acc vobebhc, be’tj shunf iam tyu humuxiamGkheqx je bhum vmu ragxewxo.
locationString = "You are \(Int(distanceInMeters)) meters from your start point."
Dam niixc opt kac. Teka xoje fwi miwovobof oh buw co u njaopom fzusi avy ysijd wevufuef vugralik. Tii’hk jio hwec ve tav ecteqay. Gawp ziju.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.