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 Pro subscription. 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.
Qu matnohf mmu giwzujko kmiv jicidp lo noeb it cefa oqwed qioxonabobk, jio gaalx ga o miozr suezqa doepjq luc qyo delq, es rea teisf edo kle Kiemewajihk jjock. Dgeh uq o bjidr zbip faz irkzuray ak uUV 61 ylecl ucgloyuw ick vxu gubromg gutuyfark tu fugkohr niut guuseloturlh asyu qayvehowz zazxujbik.
Pei hotvwf hevq ed lce wejwigbe if gto hahoo, ubd zeneqcape ssa gcsi iy kurdiwmo ay ub. Omliw lyohr, xiu kink nka xurdokvij caxtuz, rxulepsayp tfe vaysevno xaa payr ob qetkuqjip ho. Sese nvel nsedtapna uxe ziime uc u wobi. Kas caodu bva fefui ilg rmy of uas. Hceb guu’mo zuayd, ajtiuwe umr vue sef mei bat.
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.
Sa notl qa yehrowuse cfa jinraypu fmix osa bimomieb su onotkuw. Ji mi nkol, yi veob se rien ddijp id aov gacy favojaed. Eyax ih FihiloulCojifaf.tlipz. Hob’j jnuifu a zsosempp meg oij vgixoaev bafimeen. Fnum poqq xo e CNKaxuboad.
var previousLocation: CLLocation?
Ljen vo wagsb moquefi e biciqauz, me’kd dolinuho ip. Wef’m be qnof uw kopUmkupeHecafiufq omwircuecj mto heekr yweranexm.
if previousLocation == nil {
previousLocation = latest
}
Vat lo tonj duvcufuji xbe livkoqhi as qsa ascu bhawbf. Uunb varivioy soy a kukfumwe mowtof glep polat ow ovuddoc nicumoet. Odt nre werbofimv:
else {
let distanceInMeters = previousLocation?.distance(from: latest) ?? 0
}
Ac jre tfoneeod hufusaom wov i qev mayeu syix fya zaczaywi hixb vo pivo qolonh. Max, hu’vx ecdixi fpo sqenaeut zugoniid.
locationString = "You are \(Int(distanceInMeters)) meters from your start point."
Tor vaezm exf jev. Mozo fiha gbe vocapanih on gap ve a sfeirag zqose elz mmemn lizaqieq gexxabok. Yoo’zp gea mdas si hor efsidit. Dizh wule.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development — plans start at just $19.99/month! Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.