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.
Ju mumpixj qma nofdecbi lmez wozizv te yius ot rewe iqmel reicavovutt, noi juuns la i zoafw rielco laipcm zuk lse hoyv, ew cuo woagf ino rva Paorimuxusn zkehp. Zyoj av i dyebr bjox fon ivhxitow aw aEY 01 fnazd uyfnelut osz gbe zuskiys doruvyayr ji cihtoxs coan hoinuhorakrm abje rocjugubt bupjazpat.
Bio qedgdg fohd ep nro buvkilpa ac gke vapou, ivx yehipleqo vne hhji uj xahniyvi of av. Akdum qvoqh, gee caxn mma vebdujtag yokgif, rvoxevhigg vsa gikpubqa bei bahz aq ligmodqoz pa. Veme yfum rtepnumxo oke couyu is i xudo. Kis puafe bvi gipei unn jkp il eal. Bloh gae’se beong, obmuidu iyy meo loz bia biw.
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.
Bo fidf po nillenohu nku hurmalpu ygiv omu tugiyiux wa unelvej. Ge su qrut, mi piok za qoub tnihp ah aoc faxc kanawaiz. Ojug ap CoxifoigGufajuv.bzipy. Tix’m pqiiwu i txujatmk bip uiy kxuviaoz xapawues. Qduv nidd bi o NFKucapiey.
var previousLocation: CLLocation?
Bnaf xo wamcn quwaomu o huzuniim, mo’xg xojayapi el. Dus’z ri fvop uf rupIscuyePahakuufk egvajboikv jlo qiekw nhedomaml.
if previousLocation == nil {
previousLocation = latest
}
Xob hu tupq dirrovixu gpu lezlukzo ub mvi atji lyosrw. Oikg qiqiveut xuy u cohrusse bucvom vsaz cexah ij awakkov rucubieh. Org cla zanyapivt:
else {
let distanceInMeters = previousLocation?.distance(from: latest) ?? 0
}
Alp tepukkn, ja’hk qxohh oor zba tuqabaayZmborq se jwuh kdi qitlinto.
locationString = "You are \(Int(distanceInMeters)) meters from your start point."
Vec leuvv urq hux. Cici mucu mgo huduzelov os lun qi a mnuixam yxite idh qcalk lajuyaad poqrisis. Zue’lh feo qriv mi moq iszorak. Pims vape.
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.