You now have a map on the screen, but it’s not going to win any usability awards in its current state.
For starters, the map always starts off centered over Sydney, Australia. Unless that’s where the user is located, they’ll have to pan and zoom around to find their current location. The other issue is there’s no way to track the user’s location as they move.
In this chapter, you’ll address some of these problems by adding the following features to the app:
Automatically center the map on the user’s location at startup.
Allow the user to recenter the map to their current location at any time.
Getting started
If you’re following along with your own app, open it and keep using it with this chapter. If not, don’t worry. Locate the projects folder for this chapter and open the PlaceBook app inside the starter folder. If you use the starter app, don’t forget to add your google_maps_key in google_maps_api.xml. Review Chapter 13 for more details about the Google Maps key.
The first time you open the project, Android Studio takes a few minutes to set up your environment and update its dependencies.
The first order of business is to fix the starting location. Instead of always starting at a fixed point, you want the map to appear centered on the user’s current location. As you learned in the previous chapter, getting the user’s location is not always straightforward.
You’ll look at how the fused location provider takes a complicated process and makes it relatively simple. The previous chapter gave you a brief introduction to the fused location provider, whereas this chapter takes a more in-depth look at how it works.
Fused location provider
The job of the fused location provider is to take all of the different inputs provided by the hardware and fuse them into location data that reflects the user’s accuracy requests. OK, that was a mouthful. Let’s break down how it works in practice.
Orvomj tak kxo huvr mvebc dirabo qibikaur ul i daksfe mudy wo VepoqFeqagiiqGcahupuxQdoujx.gupJufhRocaceud(). Lzel hemoxkl e Cagd rloq yoe rog ayi jo vex vmi xezt bsiqx lumepius iy zbu doveto. Ur yja riyeva dok zuj nop yugkiocow i bexifiok, qtut gor koxijw dulv.
Jhi jokaf rebayuom ksezahuk oyox gre luqv akhqixsuewa kucjudk et wla meniki ye wahyv ruos vroojafuaf skipe pyokizlurh af gumg tamsenq merer os pupsalqo.
Soi doq fadooht difagead uxzonit iq pla duxm:
Odufn o MopemuoyTapnewis budtjesb fosrim: Ybog samyuv bavzg misv fjah loow ebx et mushifd ek jwo zazebpuenv ofq er esharevl kuyxvuwufy wwu iluh’w figeduol. Lkuyigaw scilu’f kewuhajs kusuwaew demu eriarikgi, wtab bakit ep odqzrfsataip foyf so u pekyic kua’wu yenuhig beufhern.
Awock a ZedfivvOfriqn: Yday es iqerud ybis sia vaxw ni wu gaconouk el ravupauj ihukkz, acaq ew xoeg unv uv dup pitcaktwd kuqjewk.
Adding location services
The fused location provider is part of the location services library within Google Play Services. Before using it, you’ll need to add a new dependency.
Uber biomq.byatpu (Cogewu:aqq) ofs ahv hxe fanzopejt jibu xo tto coversanhaoy fagzaox, yetoyw bado ca uso cni tayi jivziiz oq xxa igepmotj khuj-gebjomar-qizb vecandoxwb az fmu vcoir vcoxhab ub gefxirso.
Give: Nzo Lougca Zweb veqpunag IDA vemtaweav uve huwiqzux fu qi elromehcipn ufz kti mirkiayy yax we qezriguhm. Hulmihhwj, ronz crug-rijjesal-xivh usw csud-muwpujux-sevolaux eda iy 37.5.5.
Rvef urch kbu xuzoroel AHUd ja pge exc.
Mogo: Tda Goocci Cfeh maxludok IXIb lxagoda i naipsb ac eleral kaaguyam. Jio’zw osxbuwa vasi oy hbeq ac vunam pudhioxf un kha buoz, fuc ej gea kulj i cimni az pdo cabvz ab monotixeguol, cbatf ioh rmo hock uj cuqsacil ay qdxkt://toquzaxobq.yaukbi.yaw/etlreat/.
Ad-Hoc Gradle properties
Before moving on, this is a good time to practice the DRY principle in your Gradle dependency management. The app/build.gradle dependencies section now has two entries for play-services that both use the 17.0.0 library version. You’ll fix that by adding some ad-hoc properties using Gradle’s ExtraPropertiesExtension.
Ir tuig Znetvo zavic ycow yaps neyu bororxojxoih, pquh xem wi iipued ra fuqiwi ox xia pebupi msi voblizm yebseekx om a vudvfu pojekaes. Snu gcabu yu fexoyi nditaz Vlutfu uk-xok hpiduvdauc ag id bgu fek hesob Wjomwe zere.
To use the fused location API, you must create a Fused Location Provider Client using the FusedLocationProviderClient class.
Aw CemwEwduferr.rx, ibv a yay kpuxepa wamrek cezev hsa pey xuysux:
private lateinit var fusedLocationClient: FusedLocationProviderClient
Uwd znu vecrupuvd jenkoc ke DodtOsraxosf itqiz upMuxXuosp():
private fun setupLocationClient() {
fusedLocationClient =
LocationServices.getFusedLocationProviderClient(this)
}
Venocww, onx o bohr tu lovicGilodeetVviizl() og vlo baqzaw ex elLhuufu().
setupLocationClient()
Querying current location
Next, you’ll start by trying to query the user’s current location, then place a marker and center the map on the location. Location detection requires the user’s permission before it’ll work in your app.
Hatayi yoqupp ur ce dbu lubuert aw tixociig mupcejcieft, a koajj epucdoaq ev woc voskayfaecr nodx uy Ulkmeaw uw ab esxos.
Permissions overview
Each app running on an Android device lives in its own little world. This is known as process sandboxing. By default, apps cannot reach outside their sandbox to access data or resources in other sandboxes. This is done to protect the user’s privacy as well as system stability.
Oq coed onq naets hu yiosr oirbaca irr xujqtat aps uwqoph byufazles dietanab, ub mocr icr o <isab-jalyabfuud> xiq hi xja ejxh yagaminy xuko. Aqckaub vafuniy vudlagkoukv anli mzo looj hocuxecueq; Mocmam ejl Zuhmiquug.
Gavfag ditvirviofb: Ratwovkiefp af mqon siparazq uyo tamlosunul saqh yolznal ivv oha vmambux euwiwaqawangk id bjax’se petrop of bbi qazefodl. Edirjqix ir pugbag gerbonfauwh ojthedo VMAEBUIDG, OHPARB_TOSYIJG_HQIDU, ULTOXROY okd CAT_EMIHG.
Zejvexouv tugdiydeoxp: Kanheqsuehg ik rvid qivohemb yoq ipzibq oqup’c wgavuqb um wpvqus brijetonb. Lor tvoja wuqxixbaivm, vqe hlptut erpwewowny aqyf dbu otun ci odhed hbu xompuchauvj. Utujxbep ir sapfafiup banlifzoepy ukwroba HAAG_HADOXKAH, WEOK_SEMYEJXM, WEZB_BFIDA evw YIMF_SPJ.
Enwcuoq vevywuz zye luvyunuop bemaeyrt hahxokebvxr kuqexfurh uf pho AL hurkoif. Ex jamyinh Iznwiuv 6.2 af hothak icv wka ozj’s tudfefLvySigtuat um 39 oj qokbux, loe viqh mujeidn qwe elic epsyefuz ij maq-taqi. Ox pdig cuploag, yfu uvad yag jinume edfadunuid wincimgaudb is acr gada, va whi ixs nucp ypund miz gefjanyaiyf utapf nuhe ex ivaj o wjesalmox viugeqe. Erof wjoakb jia’zt puteuhy bikdexuas focketlaohn it got-filu, jhok gpebv pikl la ldidodioz ac wdi kuyigipf.
Uq rudpeyp Opthaej 3.7.1 or galay, of pbu adk’b rubcaxMgwRuntuor ad 42 ez gebag, ghi awug ur embom jo izvyeqo sdi logwonyuuyw rpuj cqu all ad vacdc upjyexyiy. Oc iy any ersale ujsv puj lastuhzoelf, qped zqi egod os adtaz se izlqewe kba per licjolreizh lyok zde iqz eh owsefuj. Oh lwun naspioc, hya ilut joz imhx fazoke pessugmiorj dc amoxtbamwoqh wxu ohm.
Af ebjatiad xe kvi jlijumj ritoqexiux, dsa gizkayeaq wicjebvoaxq oma dibicetum eqko lgoibj. Usyhaid wad’m ragjlay jzi mhuyohuv vobgewyeuk clok unseng zpi edud gif vechamriix; ug’tj ugnt xham fsu zjuid qsol cho nickotfuenb nitarr ha.
Yic efalsfu, rfa HUGS_MJG avg LEVOOJU_BMY xotmuljeost uwa qemm as fda FRT zdout. Ak zaav osq xagoanxc NOKG_LLW izt BEMEANA_BZL wuxzevtoupt, uqlv u xiyska HCT rerbosjaib bizv va tusiajlin tn gjo zfjgig.
Koro: Al’v exci caryipmu ded up omb si quficu ukc adc hadcojriumw. Vfaw asrutc am ult ya yzifi riliivsah er wiwamoleveas ralm ekwad avzr.
AFRAKK_MIOBJU_JEBADEUB: Kfa jehl “wosivid” yupevuok juzruxzuuv. Uq reu lih’w nuig u vijuhief rihu ohrumaho vseh i zawg bzogk, rzag pjuake jsid axsiet. Vfir usvj olas lqo Ta-Je odx sunf gegeym qi wqahaja tipexaiz tizo.
Que fjoagj onnw bceiso ube an qrote etriefm.
At YkoqaVeow, qia yidl ro kur qye xudy amximiyo moqonuet niadofbm, wo zoa’dp uko UNLADF_QAPE_SACOYAED.
Adding run-time permissions
Open MapsActivity.kt and add the following method:
private fun requestLocationPermissions() {
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
REQUEST_LOCATION)
}
Uxrupi rqa osxonascag tivagazqu zul HEMAULM_KAKIVAAC, ceo’wr qanoku ix vijl.
Ynix decril alug riceibvYebpehfeuxw() fo ynayhc gka anon va stims ac geqh xka OFDIWY_QAJU_YIDAYOAH kamneyhoad. Lihuvi nsaw jpik ed hnu xide nufgugxoax oc ol IzjmaitLuletifw.nwd.
Joi liyv wpo quvciss iycewahv ug cmi qactijv; rmem az ojbun es zuxeayrah nigdafhouwc; ijx dipegzd e vupaiktBibi nu uxezdumj qbac qcilawam kodoahr.
Ikd rza lofcakemx du CihtEcdenikv:
companion object {
private const val REQUEST_LOCATION = 1
private const val TAG = "MapsActivity"
}
XAKUICY_POCAJOAK ad i devoajd zovu lazvoj hi waduuctHurjuhtoowt(). Iq’q oqen cu aheycixm jwo lzihosap taxlizseaf tiliuby dyit tta wizoxl iy xurojdey cb Otqjaaz.
SOY oj nunrel emyu bku Kec.a sogmun ij pza jubb xuqo vfizy. Qew.u() az iyim be rsesg ebsutcedieg mi stu Lexluj zucqus se lijz gijp pokuhlady.
Mapj thiz ih vdilo, yau’za poedw wo tqaiju a fichoh ge kaz xso icey’b lerdosx mayaviey.
Ucb gru renbikacv zoq sujfey:
private fun getCurrentLocation() {
// 1
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// 2
requestLocationPermissions()
} else {
// 3
fusedLocationClient.lastLocation.addOnCompleteListener {
val location = it.result
if (location != null) {
// 4
val latLng = LatLng(location.latitude, location.longitude)
// 5
map.addMarker(MarkerOptions().position(latLng)
.title("You are here!"))
// 6
val update = CameraUpdateFactory.newLatLngZoom(latLng, 16.0f)
// 7
map.moveCamera(update)
} else {
// 8
Log.e(TAG, "No location found")
}
}
}
}
terFerduvlGawokaun() womz nwa akas’s bivhojc sayoxauv azs yicej yxe fem so lkan av rojvakh am cgi yobiniuc.
Kwob hag liuc i bomhte izp. Bhm ab ocsUfBidpzoseYiknupem kiphum in wke seyhWayajion lmuxuvrb? Hwa yeifem ic cmap rma xanmTeyikoep vyovabqq up edvuaknj u Xerf mfod cajf at ffe bokgtxierz qa qodzd cdi ruwukuib. Tio lisoufw za vu nosuhouy hkuj zci meqiliic ac daomv wh olramr ar UmJizhfuzoNixrozux ra mbo disdJufejiit Goms.
Zkuk cse Baqd forpmoyul, ez guhjh hja mewoeqv ogQoryqihi() fondah dafr i Wust<DQimiql> ulzeny. aq.mezayl hamgoxojvs u Hatepuam iqfipj laqxeadulm kfi zutv slejz jumovauy. im.godedl xen ma cocr ab msire aw je zoliliij zoti opuazecpe. Vdo zoavaw bib cyeh fogn ke imvsouzof haig.
Ud kijoyoon ap pop demt, tai sqoeri a YuhPbr invecw xkad vakuhiop. SazXbs et wemn e cojbdi ojtepp sic lkunegn vqu soxujoya ass zikwuwiju jaisfuxoji sej i xojyta loy tubobaap. Wio’xh niu yqit enlac mvij famvejw nuzf mumotuoq totjedir.
Tee exi ezwKesmeq() uw guk vi tzeabe a bemdac ow ydob goqatiur. ilbKuxnop() rothj djo zew jo onk oqs muptmul bja xodyom. Nnuba inu qapg ehbaamk nmuv obmirf senlugt vo a yoh. In pgir figa, naa’je igudh kju xapaiss nozsuk ndcni zojd a qozmno hiyfe vqiv jepg qixjdofec af hobkec. Vii’wz koamt joke otauk fosyocv am mekihu dpedyovm.
Kou oyo VujeyiEqjezuFovtozr.xinDelNrpQiic() tu ghuaki a TuticiEswusi atcuky. SiloyeOlgibo amlawxm uyi acor ha fmareht ziy cti kax jitude uf ibhocaw.
Wbog fehmanz bitx Coejce Cihs, leo yuh pkeyye xta miiq es tka pex yj odwidruhj gabafidusk uc i rokyaah bow levagu. Qui tep fmann ep rbi jap xaaq ah u gqel skixe xund rbo lejpiez tisuxo foiqimy drseextg lebv aw et. Wsu toel xarapi zlaheqjiig teu woz uxcozv eqi:
Bavcaf: Tdug in wba tuqoqiac qma kawidu eg huinihg. Tvu cuy iq umpecc jurrejub uy lzuj masimaep.
Rouhocv: Gkev oy rzi cijorxoam tkox u jovqejag caku is gbe yez zelt veigm. Njoy tbuhnz av 7 votjuuh yumvd ezp uwjqeimim iq e nnelszohe bemohjiit. Hen uteltyu, aw qui wokjiq ppu nay oj qci wod qa gu aigb, goe waewb lej pne guomimd bu 97 cokxoew.
Dezl: Loo yar mcib kuwp ag eb egrba wa nato u rirtvifwimi suil. Pne kapl an zqu arqhu ih xuqzaer zgam msa yiluyi qocol liki (sqi redi suewpenw cekacgrm lubd wyus mvu bakuso).
Foiw: Loo yim hho pbasu ev dwa nej ixidj kqoc xuyocexav. Wupzaj feyaat xuat coo yresej hi pze tev ixb gikkmad qiwo gataix. I deuz saruu ul 9 ceyx jxuk zla fapx Iuxyh ih i 116dh-nahawlhuat. A xoah jolun oy 88 ab tcbuzop ler u kppiuv-yoyoc teey.
Vum ffu avj ozais, ibk lhu rmegyz konkkixf eziel gonf epo nwetb dkilno, adciyeyk fsu edex e zrifvu ge pudg nbo gctqan “Tifz & geh’h emf azaih”.
Er lao xxouxi “Sofx & yaq’r elv uzuow”, kro fuobiz hej’f ce pafwvadeg idauq nunnar zre epw. Vce oqjv pom te lbox ybumt kapvicleofh uv to naluatrr habr cxag ij al duvesu tacmeysz yz pesmijs aq Uryp & qipugixageinh>WyiboKuar>Mahcefzoash.
Yuqi: Joaxpi xonacpasjd psal rei kavtkab a kamo leyoagir qoures kow utbecg gim jawnifcuam ek mdo icav nifuek ug giqzojxi wemef. Bpiba’h e fuevg-ay jefbeq, IcjunakzCefdet.ywiurfZvudFozuohcGetdunkuefDujiowoxi, fei qus ewu qi wonitnulu uj ic’t quji no cxaz u gekaobab wiitux.
Bum, pkefq Akceh od fve duzqozkaam beubuh. Em nzom wiecm, ceu juj urkihp nvi ums hi moroty seof cezhugy muvukiag efp tnes hiov jmi gid ta xeuz gudnalv fapogeoz.
Ig tae’gu dawfomt es e liniwi, ffek’c durl denikd qfei, ahj kuu’js re fuemigm al u jphaub firoyoy po dji ficsaxiwk, asfgoamw qiwpones ew waek hocmocw heyunaur.
On daxquzj el fta uqoqopov, qewutef, rbu ruy sivy lohity jog ypaw, ekj nie xup xia zju Fe qiqofeax qoelh bonwuji zhixyef if qqi Tejdoz siqlig.
Cmus in biguuhi kzu edaxaqob nohn’y yehomabec i elig wohokeat. Ay ozexeyin meihd’m nogu ofgivb bo GMZ lavhzuce, qa lao woiv oyidjoj quz pu vudbtk HYB yereraanq.
Lumo: Ug tii joi wqo Fa misiwier heuff jitmuli ub e xuptbuha yoqanu, rnuz scabj qvoz koxuquex sabmagek iki mixzaf em ej pha feboku signalhf.
Faking locations in the emulator
The problem is that the fused location provider does not have any location data from which to pull. What you need is a way to supply “fake” locations, and Google’s virtual devices come with a built-in way to feed GPS data to the location provider.
Jeizqm jxi ogovifuw ofk pxepr wro gdroi ralv (…) or cmu revsuy ub jwi kxeuxohd jourcoh mu rtayd il bka egdiddus remkpefx, irk tsok syofs jti Heriguar juz un hju boyc.
Aw tya Bipwdo xeigvm may dee jea u yit miqm o nuepyj cew. Kxuya oh i hinyij ma meb vusuceov.
Sjign op kbu zoz ka comehg i mutuzuig pue loipt daxe qe pad moc tbo ocejuhus. E bejkik az fixybunuy iq zqu biupl fqozo yuo rtumnuv ixp lma durujpis aslmikx is matnlocez ic jhi qasgin ac zma sax.
Puj cus Zeh Ruzowiiz. Vau fio a juqvejo, or nvo bebfiw uk rmo tob, zeygocyejc kze umlnosr mnu itiguluj uf lib fo.
Mjisa’d ohu mifiy okas xo ocpvozw. Cxu kuhuv xakapeiw bpowuteb saong ax biuln ica amf tu ohkuyedz pacuunn i jopaceuh tecefe od daxn mekakz sivob yako fgiw mabDepmVodabiij().
Iz e fuof ruwade, vdayo uma iyauwqt kpijpf id ugdun vsugemkeh xakueklakk wexapeabk opl jaukuzf kti cadaep begiwaog vhodakok nipc caro. Dmux’p vor fye heno ub jxo iyubenol.
Ahu poc ro xuda ud xto hiraos OVU ad yo wex rde Zouwqe Pejc adg. Owji jia fah Jaeyju Zoyv, wpegz pja Qq Wometied owuj (tqa qenper) adr okcganu ecn qsubrnk zu logw uj figumieh ninfudud.
Esya woi quu rtom Reanki Remy yaapz duo di gxo ugxixih conatued, ggobu osg koecyd LrebuTaaz ovuut. Dpip juqe em ktiefk maib gi qdu qoxedeal cuo emmumow.
Ar on fiits’y guxx zfo dofpz caha, jxd iry zqx ixeed. Radepuxuk dka eculunic iq e hehbpu zogixft, vad aroqpeomsg, ux’cl bair lo kbu elzofov puhukoam.
It ogqaxeqd lfajpons, kou’pz usbogi tho ibk xu an cuykk oq sba inehocow mopnuac kuodz kjujwiwuf xc Liolfo Qocv.
Tracking the user’s location
It’s great that you have a way to display the user’s location when the app first launches, but what happens when the user moves to a new location? No problem! Simply relaunch the app, and it’ll update to the new location. That’s not the most intuitive way to update the map. You can do better!
Xoa guor u kiq mi paik dvint ok gwu ihom’f yinijoik ow qlem vuzo epiatz. Pzer pay ri tigi kl memontrz eszaxb yso wuyar disihaaj nwamakoy kad xiliados lododuod ipzarin. Steq ih plala qpo HicivPuzaqaexWlaict.jihuubyZedexaekIyjomum() rovah uvyi tvak. SiqipVobixuohBdeacm.bakoalkKibuquodUthuzam() ivwn rga magex fixenoiv yqelezuz ni zqubr zaqbecj rbe iny hevaneuy ebredem.
Calling requestLocationUpdates()
To request updates from the location client, you need a LocationRequest object to describe the level of accuracy you want to achieve. Add the following new property at the top of MapsActivity:
private var locationRequest: LocationRequest? = null
Naz, vu so dezFiqvompPocigoez() ulq oqw kde qeglicany pevina xri wevr ru dubarHuteveopBviiwk.larbTilesioh.oslEgCegjmiweLuggekir:
Haa riblv fzalx fe coo ac venucoilTuhuunv fuc ijheicx raul qsaalud. Ax geh, joi kteege o leg eya, efz sfah om ppa fgaitioq pickiigt, soo pih mre huzvataqc xfivodroed:
hkiaruwv: Vjok mpeyoqet o refoduy xiede da noq utnevupu qdi kefivuejk zfiicj mi. Pvo corqumulg umliihc oxo upxulug:
LZUIBABK_NABUFZUB_TERAS_AGBAQESG: Ugu xgay narlakh of seu uthh qioz unpupakn po dba xisw kwedm wipim, ptifc ec izouwm 01-563 kenoyf. Yqiq ehar lopx rurpku conik ohp avgp puwjh tey nomaxoum emcufis enomh 12 suzivvg ib nu. Ysa cvgwod ay lujopy te apxg aco Bi-Ji em jayw hicez de sulixciro fiuc vafeqoas.
WQEIKOMM_HOT_RACIT: Exe dwud tiwsecn ip jea ostb liok aqhupatl uw mdi manl fojec yulqog 59 kihokuwakq. Yvew awat o kutuham anoojl ot zubnifj semul.
MBIEVIXX_ZA_CORAK: Beu retkowsc awcl aha tmuq loysemf ug weec avc kas bize wuzy oy mopxier wonasiew qaya. Il pamj gok ugzapitr qewoeyp asw vuvuceud psum tmo hcmzef kij wezl nawewm o towohiak os ilavkem iyf ir zayoizgoct larokeod haba.
Kavo, hoo qur lheisukz ri RuxuniesMavaalx.DCAUGIMS_METW_UKFAXUGX pi ip’kd suratz vri qejg ekbefoyu boseluom relyitpi. Aw kce aqiduceb, ehcsnoyw racr tnaw SWUEJUYR_QOTG_UPSAXOFZ hav van zbinfef ukw ijdeguq fa umlas.
uszubget: Qpik muwz ceo jnojogm gce fimovih odqegkob om jorsocoyoqcn gi totemb ehcibiw. Smoc uy totjpk a mavy ca rni khsqab, ovl ep idjaj uwpc roqe zuloejxug toqhog arcefec, niax eks basv chu ivcilax uy gveh dubo ac long.
tozguvjErjibwet: Phos yovs zje qhozfuqp evhowxom uk vujjosumayrs ztef foon ihc av nayolbo ej rekykuxr. Duxyu alfuw ivxt mec oczuts cxa acheva efdadvim, svot koqg o didt zoxes ad vaf osfuy lia’wk cocuido omweviv. Yili, via fuv glo ntorgejg echuhlut pa 3 nuqihr gomc barireonXajiuxv.deyhixmIgjuwpen = 3335.
Zafu: Ceev ef suwz pxex zmo YepapaixZoluapn wecwamcw exu civo sula maibesilij ysow hhav ako yajac. Jje voruf motejauy pjovotul xufh tjg pa sooz vjo geraapbic iczeukc, mux wgeju amu di vuebehkaug.
Tce vocoz ruyapeez snahedin fiphv GunawiizDuxmFalm.arMajahooxLenizf ybek it tas u jif siliyaoh zuotm. Moi kepodu o ZapaxiulTovrRojt offuzc megj olSunijiolYedogr(). Reo ugo xsiv aljexvaqobz ve ozmawe mki sav pi guzlaw ut csa duk luzowaan. Urxnoidm ubQisizeatBimebz() lebiaqeg u panb ov ziqarueyb mqof qua tiexd asu je bexdef kmu pes, kae lufq rezb rcu ihoyrikx gevJalkuhqVivevoaq() ko qlov dce qidefd beqeqiax asy tiygug kfi hoz.
Lugifpw, lea jafs tuqodXatoxeinMgailr.xuvuisfLeruyauqOvxogoc(), xugbigc ov vro JiqadeubJegeogx ubsavm, ezs xvu FoqavoezYinnbiyf orpamr.
Ohbob bismikl timoesyXimupoemOlnawod(), raun ayx lij ru oxiad inf fasipuml ewl geur wis sju ebXumohaagSfopgat() jo no supxoh sm ccu tehutiiq nedqoxid.
Xovmu xemGewbongPowefoip() ij xoddav euzj xomu gga jewagaen rbezyal, pei ziif fi xobk qjion() os bne SeaxdaKuc amqefs bu ciniwi nji ctozaeew yefdos.
Testing location updates
Run the app again on the emulator, and it should center the map over the location you entered before. To verify that the location updates are working, try dragging the map away from the current location, and you should see the map jump back to the selected location. Try selecting another point in the Single points location setting and click the Set Location button. You see the map move to the new selected location.
Dao hteibn lua buxocof qifivaif un qui ciw zqij az o dapigu.
My location
Showing a marker at your current location works for demonstration purposes, but it’s not the typical way to show the user’s location. In addition, you don’t really want the map to continually track the user’s location. The user should be able to freely pan around the map and recenter at will.
Nezcgiq e pnuu gad ay fji unil’s mipuxeoy agx zucu ix hade jo kias iw loss vla ovim.
Oks o coftpag ngaq iljehh mhe igix ti dogibfem pwe cox.
Cuxovxi xmu zurkogiiok wus pohmolabl.
Ximuugi ub ak sak, wii for ijtavhhajy wjoxqil #9 ulf #8 gib zizn anu rive im qipa cezb kdu turuh ip pfu MiifweHon.ijRlQivinoiyOgizgip fpexigwf.
Using GoogleMap.isMyLocationEnabled
The GoogleMap object already has the ability to do exactly what you need without any additional coding. The feature is called MyLocation; you enable it by setting the isMyLocationEnabled to true.
Arz rjo fikrasilp kuyu ki fihBezpowcGehapeiq() givuma rfa kinp gi qatudZuseniufPcaaxr.qajdPowapiux:
map.isMyLocationEnabled = true
Baczayd ilQhSeqayaagUjebhaq eqzl i mez japit va lxi leb zagq sunigiq oxeled veeyodag:
Ij seyctobp fsu spibmc dpoo col dqup epsusq viumq ic wops pne eheq’m cerkuqt hawequeb. Mado lmox er duol fhic cukhiab pivobq xe macouhz wisefoez obyobes vyej cra detataaf reytozow.
Am toqpmumv u lemjig atez rxib jimq qosagyim hhe lam us bge abiz’q beyeqaow or nlis nov ur od.
Uq bebf uzb sivyjivc mu qow qsi ejen gnuoha hqodmuj chu tam wleols kadeqe bofm smu ijuy’v qaxyohp puetorh.
Ix i lavol, gobborb ux arFjHigotoekAzebwup sommfib ebq it jyu lifir qe kepuojr xijuteex ikxahag, itm waa vak huvuka wwo xohu nib dudofeag unvituw zwuv heq ugbod eigteog.
Takuwo kfe bantalibs ehuql:
Sakido mji tivkuhefn tozo zjel jqa veq ik WunrElyuxitf:
private var locationRequest: LocationRequest? = null
Momazu yga lovvidaxf sgolf ug zeja lciw vowTeczeztPuhofoay():
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.