Tải bản đầy đủ (.pdf) (108 trang)

Tìm hiểu dịch vụ googlemap xây dựng ứng dụng chia sẻ vị trí với bạn bè trên nền tảng android

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.35 MB, 108 trang )

CHVONG 1. Glen THISU BAI TORN
1.1. Vai net ve GoogleMap
Nhu citing ta da biet, bit chip suy thoai kinh te, nganh ding nghe thong tin van
dang phat trien v6i mot toe dg cheng m$t. Trong thbi gian gin day danh diu sy phat
trien rat manh cua cac thiet bj dien thoai thong mirth (Smartphone). MOt trong nhung
(mg dung quart tong nhAt va co the nal la "khan the thieu" d6 chinh la ang dung ban db.
Ban d6 GoogleMap duqc xay dung ben ceng ty Google bang the hinh anh vg tinh
va viec di tim hieu throng ph6 thuc te. C6 mot so than vien cfra Google duqc tra ltrang
cao voi c8ng viec dap xe dap c6 gin thiet bj cita Google de ghi lai va chyp anh dutmg
ph6. Cong viec nay ton rat nhieu thbi gian, nhung nha d6 ma ban d6 GoogleMap co dO
chinh xac rat cao va nhOt fit thutmg xuyen. ling dung Maps hay chinh la
GoogleMap gulp ngutri dung c6 the sir dung ban d6 nay trong viec tim duang di. 6
phart sau toi se gieri thieu ky han ve ung dung thy.
1.2. Nhftng gl GoogleMap khong ht) trq?
DOng hanh v6i su phat trien cfut ding nghe, new nay each con ngubi giao tiep
cling di kit di. ChAng ta khong chi chia se hinh anh, loi nei, van ban ma yeti thiet bj
di dOng thong mirth ta con c6 the chia se ca vi tri ciut mink. Cac thiet bj di dOng thong
mirth hau het deu tich hqp tinh nang GPS — gitip djnh vi Nei tri sir dung tin hieu vg tinh.
Ngoai cac eh& nang co ban ma GoogleMap da cung cap nhtr tim dtrimg, chi
dutmg, dieu huang... co mot chirc nang quan trong khac ma GoogleMap da dimg
trq da la firth nang chia se vi tri vUi ban be, ngutri than(Google Latitude). Chinh dieu
nay da thitc dAy ten xay dung mot (mg dung chia se vj tri ban be teen Google Map.
1.3. Tai sao lqi cAn ting dyng chia se vj tri?
Nhu ta da thAy, co se dft lieu de luu aft da lieu ban d6 ctia ca the giOi la rat 1611,
hay c6 the not la v8 cling lon. Chic chin khong the nao luu trtt tit ca cac dia diem, cac
nha hang, dja danh tren ban d6 duqc. Cho du Google co co ging lam dieu do thi dft
lieu se khong the cOp nhOt thu?mg xuyen, trir khi moi khu ph6 tren the giei deu co than
vien cita Google. Chinh vi v$y thing ta co the S thanh mot ngtrtri clang tot bung,

bang each giam di ganh n$ng rill* dja diem cho Google. Chang ta c6 the to cop
nhOt vi tri cilia minh. Tuy nhien, khong phiti bit tit ai, bit cir lac nao ta cling mutin chia


se vj tri cfta minh. Doi khi ta chi mut% chia se yen ngutri than trong gia dinh, hay bon
be ma then... Con nhieu van de !chic nfta, nhung da chinh la ljf do de WI xay dung
chuong trinh nay.

3


1.4. Mei truirng boat (long
Chuang trinh nay se &gm xay dvng tren he dieu hanh Android — MOt nen dang
phat trien rat manh tren cac thiet bj di dOng — vi sir dtmg Google Map API.
1.4.1. Tgi sao ding Android?
Android la mOt hg dieu hanh ma nguan ma, chlnh vi the nen ne duqc phit trien
rat da dang theo nhieu hue ng khic nhau. ChInh dieu da da &rip cho cac nhi sin xuAt
clang hon tong viec cho ra nhUng sin pham het sirc da ding, gifip
thiet bi di ding
Android c6 s6 ngteri sir dyng kh6ng 16. Ben milt 46 gii thanh mOt thiet bi Android
ding re hon thiet bj chay IOS hay Window phone ma firth ruing yin kitting he thua kern.

a

1.4.2. Google Map API la gi?
Google Map API li mOt Giao dien 1#p trinh img clang do Google cung cap. NO
glop cho lap trinh vien c6 the sir citing chinh bin d6 cua Google de xay citing img dung
cila mirth. Tuy nhien khong phii tat ca the firth rang cua Google Map day di dau duce
cung at) a day, chinh vi the ngubi 18p trinh vien phii tim each sir clang th$t Idiot) leo
de giai quyet cac van de bii toin (tat ra. Chi tiet ve Google Map API se duct de Op a

pitan sau.
1.4.3. Server qudn ly hogt Ong
M#c da Google Map API cung cap cho to mOt ban dO tuong d61 hoin chink,

nhung da chi li img dtmg ben phut ngubi dung. De ling Mpg c6 the hoat ding can c6
mOt Server. Server nay c6 nhiem vµ luu thong tin tai khoin cua ngubi dimg, luu v1 tri
ngubi dimg vi thvc hien mOt so chirc niing khic.
Server nay can ducm via bang mOt non net ph6 bien vi khong phv thuOc vio
hg dieu birth, da chinh la nein ngft Java. Server khong an c6 giao dien 46 hoa, chi co
nhiem vv nh#rt yeu tau tir phia thiet bj kith, zir ly vi tri ve ket qui. Tuy nhien, da la
ding viec cim ngu&i 1#p trinh, ngubi sir clang img citing nay khong an quan tam server
lam gi ma chi can thao tic tren thiet bj dm mirth.

4


CHUONG 2. GIefITHIEU a DIEU HANH ANDROID
2.1. Android la gi?
Android la melt Hg dieu !Anti dinh cho cac thiet bj di dOng nhu dien thoai thong
minh hay may tinh bang. Android duqc xay dung Iron nen tang Linux va sir dung nem
ng0 Java.
Ban du, Android duqc phat trien boi TOng cong ty Android vii str ho trq tai
chinh cua Google. VI° Min 2005, Google di chinh that mua lai ding ty nay. Tuy
nhien vao theri diem da Android van chug duct ra met. Den aim 2007 Android mai ra
mit cling yeti tuyen b6 thanh lip Lien minh thiet bj elm tay ma: mOt hiep hOi g6m cac
ding ty phan mem, phAn ming va vien th8ng yeti mac tieu day math cac tieu chuan ma
cho cac thiet bi di dOng. Thief bj du tier chug Android duqc ban ra thing 10 mitn 2008.
Android la he dieu hanh c6 ma nguln ma va Google phat hanh ml nguln theo

gily phip Apache — mOt giay phep kW:Mg c6 nhieu rang butjc. Chinh dieu nay di glop
cho cac nha san xuet thiet bj, mpg di dOng va cat lelp trinh vien duqc dieu chinh va
phan phOi Android mOt cach tar do. Tinh den thed diem thing 10 niun 2012 — 4 Titan
sau khi thiet bj Android du tien duqc cong b6, di ce khoing 700.000 img dung tren
Android, va s6 luqt tai ting dung tree elm hang 'ring dung Google Play &cc tinh khoang

25 ti luqt.
Chinh nhUng uu the nhu v1y ma Android di fret that nen tang dien thoai di
dOng thong minh phO bier nhit the gi6i, vtrqt qua Symbian vao quy bOn nim 2010.
Android duqc cac c8ng ty c8ng nghe sir dung khi h9 an mOt hg dieu Minh khong mItng
ne, c6 kha ning tinh chinh va gia thenh r8 chay tren cac thiet bj cong nghe cao. Ket
qua la mic du duqc thiet ke de chay tren then thoai, may tinh bang, Android di xuit
hien tren nhieu thiet bj khac nhu TV, may chai game va nhieu thiet bj 'chic.
Tinh den tit diem quy ba nam 2012, Android di chiem den 75% thj phlin dien
thoai thong minh tren town the giai. CO tong cong 500 trieu thiet bj di &Km kich hos
va 1,3 trieu luqt kich host moi ngay. St; thanh c8ng cim hg dieu hanh nay cling Man
ne frac thanh muc tieu trong the Ai hen lien quan den bAng phat minh, hay can gui la
"cuOc chien dien thoai thong rninh" gift cac c8ng ty ding nghe.

5


2.2. Lich sir phit tries
2.2.1. Sy! ra del cues Android
Tang Gang ty Android (Android, Inc.) duqc thanh lap tai Palo Alto, California
vao thing 10 nAm 2003 beri Andy Rubin (thing sang lap ding ty Danger), Rich Miner
(clang sang lap Tang cong ty Vien thong Wildfire), Nick Sear (timg 11 PM giam doc
T-Mobile), va Chris White (truing thiet ke va giao dien tai WebTV) de phat trier, theo
to i cita Rubin, "cic thiet bi di &mg thong minh han c6 the biet duqc vi tri va se( thich
cita ngubi dimg". DV nhang ngutri thanh lap vi shin vien deu la 'tang ngubi c6 tieng
am, Tang cong ty Android boat dOng met each Am thim, chi tiet 10 r&ng hq dang lam
phan mem (lath cho din thoai di dOng. Trong nAm do, Rubin het kinh phi. Steve
Perlman, mOt ngubi ban than cita Rubin, mang cho Cog 10.000 USD tien mat nhtmg tit
ch&
. tham gia vao cong ty.
Tang cong ty Android duqc Google mua lai vao ngay 17 thing 8 nAm 2005, bien

n6 thanh met be phan trvc thutic Google. Sau thucmg vv nay, nliimg nhan vien chit
chat dm Tang cong ty Android An tiep tic a lai cong ty lam viec. Vao thbi diem da
kitting c6 nhieu th8ng tin ve cong ty Android, nhtmg dA co nhang loci clan rang Goolge
dir tinh tham gia thi trutmg thiet bi di dung sau buem di nay. Tai Google, them do
Rubin dung du dA phat triers met nen tang thiet bi di dOng tren nen nhan Linux.
Google quing bi nen tang nay cho the nha sin xuid dien thoai va cac mang vien thong
ding 16i him se cung cep mOt he thong linh hoot va c6 !chi nang Wang cap. Google dA
lien he vii hang loaf hang phan cling ding nhu dai tic phan mem.
Ngay 5 thing 11 nAm 2007, lien minh thiet bi cam tay ma, hay con gqi la Open
Handset Alliance, met hiep Mit gem nhieu cling ty trong de c6 Texas Instrusments, tap
doan Broadcom, Google, HTC, Intel, LG, tap doan Marvell Technology, Motorola,
Nvidia, Qualcom, Samsung Electronics, Sprint Nextel va T-Mobile duqc thanh lap
shim mac Bich phat tries cac tieu chuAn ma cho thiet bi di Ong. Cling chinh thbi
diem de, Android cling duqc ra mit yeti vai tr6 la san phatt n Mu tien ciza Lien minh.
Chiec di'en thoai chay Android du tien duqc ban ra la HTC Dream, chay tren nen tang
nhAn Linux phien ban 2.6, phat hanh ngay 22 thing 10 aim 2008. Su trtmg cita
Android la met con Robot mau xanh la coy do hang thiet ke Irina Blok tai California ye.

6


2.2.2. Cdc Alen bdn Android

a. Android 1.0
Ra mat: 23 thing 11 nom 2008.
Android 1.0 rat nguyen sa, tich hap sin khi rang deng bO der lieu yeti cac djch vu
trqc tuy'en aim Google nhu Gmail, Google Calendar va Contacts, mot trinh phat media,
hit trq Wi-Fi va Bluetooth, thanh tang thai hien thi cac thong bao img dung va mot
img dung chap anh (camera) tuy chua cho phip thay doi dt) phan giai va chat luqng
anh nhu cac thiet bi ngay nay.

HTC Dream la don smartphone thucmg mai ding Android du tien v6i kieu
Bang tract kem ban phim vet lg. Phien ban Android 1.0 chua duqc Google ct(ft ten, do
truck 46 ten g9i Astro Boy hay Bender.
b. Android 1.1
Ra mat: 9 dying 2 nom 2009.
Ben quilt so phien bitn, Google da bit diu dua he thong ten g9i vio cac phien
ban Android. Tuy chua chinh thirc itp dung nhtmg Android 1.1 da c6 ten Petit Four.
Kitting bao gem nhieu tinh rang, phien ban nay be sung mitt so chirc ming meri cho
Google Maps Men thi chi tier hart, ban phim a° g9i dien thoai da c6 the hien thi hoc
An Mil gqi, chucmg trinh SMS cho OCT ngubi dung luu tap tin dish kern. Android 1.1
sirs mot s6 loi trong Android 1.0.
c. Android 1.5 Cupcake
Ra mitt: 30 thing 4 !Am 2009.
Cupcake, ten diu tien ip dung cho phien ban Android. Cupcake mang nhieu tinh
nang meri nhu ban phim io c6 kha Wing chr loan tir dang go, tir dien tir nger do ngutti
dung at ra, ho trq widget tren man hinh chink, quay phim va phat lai video clip, luqc
sir then gian cuOc goi, the 40 to d'Ong xoay man hinh theo hueing sir dung (screen
rotation). TrInh duy'e't web trong Cupcake c6 them kha nang sao chop va dan.
Ngoii ra, phien ban nay cho phep ngutti dimg hien tit hinh brill trong danh ba,
mot diem thu vi ma hku het ngtroi dimg dien thoai di dOng muon c6. Man hinh chuyen
tei va hinh anh khi khoi 4Ong may duqc lam m6i.
d. Android 1.6 Donut
Ra mat: 30 thing 9 nam 2009
Donut nang cap cac chirc nang trong phien ban Cupcake, met Ong chirc rang tim
kiem bing giqng n6i va ky to den bookmark va danh ba. Android Market tit thanh
kho img dung chinh de nguiti &mg tim kiem va xem cac img dung Android. !ling dung

7



chyp anh va quay phim trong Donut nhanh hen. Hg dieu birth ho trq man hinh cep 40
phan giai 16n ham, huOng den clic the hg smartphone min hinh km.
e. Android 2.0 Eclair
Ra mat: 26 thing 10 nam 2009.
Chi sau gin mOt than ra mat Donut (Android 1.6), Google tung ra Eclair, phien
ban dugc nhan djnh la buck di len dm he dien hinh nay.
Eclair c6 rat nhieu chi tien, tit giao dien den (mg dung ben trong he' thOng. Ung
dyng chyp anh tang cubng them chitc nang zoom (phang to), can bang trAng, ha trq
den flash va cac hieu img mau sic.
th0ng hoat dOng On djnh hen, cal thien kha nang xit 1Y, hi5 tug ket not
Bluetooth tot hen, dac biet thy chcon ding hi) nhieu tai 'Moan. Met diem thuan tien
dugc danh gia cao lac bay gib la giao dien danh ba cho phep nhan chgn vac' mOt anh
danh ba de g9i, nhan tin hay email den hq. Giao dien img dyng Lich bleu (Calendar)

He

cung dugc thay dOi.
Eclair IA phien ban Android du tien ha trq anh nen dOng (live wallpaper). Tuy
nhien thy chqn nay tieu ten kha nhieu pin vi titi nguyen may.
f. Android 2.2 Froyo
Ra mat: 20 thing 5 nam 2010.
Tir phien bin 2.0 tro di, Android &I din hoan thien hen. Phie'n bitn 2.2 (Froyo)
duce tich hqp Adobe Flash, keo theo hang lottt img dyng va game. ND:raj dung ding
c6 the xem video clip nen Flash nhu YouTube va "ra lenh" thyc hien cube goi qua ket

net Bluetooth.
MOt chic nang mai trong Froyo dugc them ngubi dimg luu dOng yeu thich IA
USB Tethering va Wi-Fi Hotspot, thin chiec smartphone Android thanh thiet bj phat
sang Wi-Fi to ket net 3G. Tinh tiling nay dugc sit dyng rat phi) hien den ngay nay.
Len diu tien Android cho phep chi dat img dyng (app) len the nher SD thay vi

mac djnh chi ngay vac' b0 nher trong cita diet bj. MOt chitc nang mei cita Froyo do la
mat khau di ha trq se va chit se. Thiet bj du den mang nhan Froyo ra mat thj trubng
la HTC Nexus One.
g. Android 2.3 Gingerbread
Ra mat: 6 thing 12 nam 2010.
Den cuOi am 2012, Gingerbread yin dang duce sit dung eon rat nhieu thiet bj
dimg Android, chiem den hen mOt nira (54%). Google hqp tic Samsung trinh lang
dong smartphone diu tien sit dyng Gingerbread mang ten Nexus S, ha trq cong nghe
giao tiep tam gin NFC.
8


Gingerbread dua vao he th6ng met ceng oar quart 15r tai tip tin, cho phep theo dei
va truy xuit den cac tip tin da tai ye may. He thong nay hiS trq nhieu camera cho cac
thiet bj c6 camera mit sau va trtrac, quan 15r nguton pin hieu qua han, fiat kiem thin
ltrang pin. Phien ban nay khic phuc !chi nhieu loi tir Froyo, kern theo met so dieu
chinh trong giao dien ngtroi dung.
h. Android 3.0 Honeycomb
Ra mot: 22 thing 2 nrun 2011.
Day Hiring chi la met phi'en ban, ma ce the xem la met the he Android du tien
anti rieng cho may tinh bang (tablet), ra mot cling tablet Motorola XOOM.
Mang nhemg firth nang tir the he Android 2.; Android 3.0 cal tien giao dien phit
hqp veri each sir dung may tinh bang, ban phim ao than alien han, h8 trq xir 13 , da the
vu (multi-tasking), cho phdp chuyen doi qua lei cac ling dung dang cling chay. Kherng
chi c6 be mit dirge trau chu6t, phin lei he then c6 the cal tien ttrcmg thich yeti plan
ding nhu hO trq chip xir ljr (CPU) da I8i, tang toe plan ding...
Android 3.0 dit nen meng quan trong cho the he Android 4.x hqp nhAt, 'chic
phuc stir phan mang cila Android (c6 cac phien ban rieng danh cho smartphone vi tablet).
i. Android 4.0 Ice Cream Sandwich
Ra mot: 19 thing 10 nam 2011.

"Ice Cream Sandwich" (ICS) la the he Android dirge mong dqi nhit den nay, ra
dtri ding ding smartphone bom ten Samsung Galaxy Nexus, the hg smartphone diu
ten sir dung ICS.
Android 4.0 dua chirc nang truy xuat nhanh cac ling dung thutmg dung vao phir'
ben duOi giao dien chit, thy bien widget, sip xep vi duyet danh sach ung dung hon.

a

Cac img dung a c6 the truy xuit nhanh tir man hinh khOa thiet bi (Lock screen), vao
thtri diem d6 cac hang san xuAt thiet bj chi mai cho phep Camera ce the chan nhanh tir
Lock screen. Ice Cream Sandwich host dOng muqt ma, nhanh va dpp han cac phial
ban fru& d6.
j. Android 4.1 Jelly Bean
Ra mit: 9 thing 7 nam 2012.
May tinh bang Nexus 7, san phim hqp the gins Google va Asus, lit thiet bj diu
tien sir dung Jelly Bean. Android 4.1 'Ling dm hog dOng cho he dieu hanh dua
Google, tit thenh he dieu hanh cho thiet bj di dOng hang diu hien nay, de daa ca "8ng
lan" Windows.
KM ring sip xep giao dien chit va widget tong Jelly Bean c6 !dui nang thy bien
cao va rat linh hoot. He thong hO trq dich vu vi dien to Google Wallet, dic biet trinh
9


duyet web mac djnh trong Android duqc thay the bt5i dai dien ten tan: Chrome, yeti
kha neng dOng ba du lieu theo tai khoin vai ban Google Chrome tren may tinh.
k. Android 4.2 Jelly Bean
Ra mat: 29 thang 10 nem 2012.
Chi sau gen nem thang ra mat Android 4.1, Google nep tyc tang cep cho
Android vii phien ban 4.2 va vin mang ten Jelly Bean.
Android 4.2 tiep tpc mang den nhfing cai tien hap din cho (mg ch,mg chop inh

(Camera) Sur HDR, Photo Sphere, hieu (mg link Google Now, dua tinh nen luta
chqn to rat hay trong ban phim so. Chirc rang ho trq nhieu tai Idioan ngutri dimg Ian
dau tien duqc ap thing trong Android 4.2 nhung chi c6 ngutti den may tinh bang thin
huerng chile rang nay.
1. Android 4.3 Jelly Bean
Ra tat: 24 than 7 nem 2013.
Android 4.3 Iii la mot fling cep non cua phien ban mang ten Jelly Bean. Phi'en
ban nay hi) them tinh nang Bluetooth rang luqng thip, OpenGL ES 3.0, tit) , chqn Wifi
luSn bat, hi trq ngon ngit doe tit phai sang trai...
Vii phien ban dui ba mang ten Jelly Bean, Android dang din hoan thien han, yeti
nheng tinh neng mai, Android hila hen se thu but nhieu ngay cang ngutri sit dung.
m. Android 4.4 KitKat
Ra mat: 31 thing 10 nem 2013.
Mac du rat nhieu nguiti de do doin phien ban Android mei c6 ten gqi "Key Lime
Pie" trong suOt mot thei gian dai, Google de cho ra mat phien ban 4.4 vii ten gqi
KitKat. Android 4.4 KitKat bao gem rat nhieu ruing cap trong he thOng va (mg ch,mg,
nhung diem net bat that ciia phien ban nay de la he try cac thiet bj co cau firth that)
hot. KitKat yeu eau be the tei thieu (RAM) chi la 512 MB, giiip cho cac thiet bj cAu
clang.
hinh thep c6 the thing cap va trai nghiem mot cach

a

10


2.3. Kien true 14 diet' birth Android
Applications l

Applications Famework


to chuc Ling Liumi

Android Runtime

Libraries IH;1

(Thai

'Tan chay Ar droith

Linux Kernel '.

HIM 2-1: Ctic think pkin csia kf dl kink Android

2.3.L Lima Kernel

DOi vei nhCmg phien ban truer, Android duct xay dung teen 130 than Linux 2.6
cho nheng djch vg cot lei nhu security, memory management, process management,
network stack, driver model. BO than nay lam tillitm vu nhu mOt lap trung gian ktt
not pith' ring thiet bj ya phan *rig dung.
time

Anima('
NDK
apps

Android

SDK

241

apps

Android app framework
Standard libraries

Mink 2-2: M6 kink kw tic gilta may do Dalvik vi Native code

JNI: Java Native Interface (Tuang ty Ichai nitm Application Programming
Interface) la mOt 13 0. framework cho phi!) ma lOnh vitt bang Java chay ten may ao java
11


c6 the goi hoc duqc gqi boi met ung dung viet bing native code ((m g dung duqc viet
cho met phAn ding cu the va tren met he dieu !faith cu the) !mac nhUng be thu vien
viet bing C, C++ hoc Assembly.
Bang cfich sir dung NI, Android cho ph6p cac ling dung chay tren may ao
Dalvik c6 the sir dung nhfing phucmg thirc ductc viet bang cac ng6n ngft cep thAp nhu:
C, C++, Assembly. Qua de cac nha phat trien ling dung ca the xay dung ling dung dua
ten cac be thu vien viet bing C, C++, Assembly 'them tang Mc de thuc thi cim ling
dung hoc sir dung ntrang firth nang mirc thep ma non ngft Java Ichong hie trq. Tuy
nhien ngtrai phat trien ling dung an phai can nhac su gia tang de phirc 4p cim ling
dung khi quyet djnh sir (king cac be thu vien nay.

2.3.2. Libraries
Day la be cac thu vien xay dung nen cac chirc nang chinh dm Android
System C library: Day la tOp cac thu vien he thong. Thu vien nay duqc viet
bang ngon ngft C, C++ chuen c6 the pi duqc thong qua giao dien Java
Media FrameWork: Day la be thu vien h6 trq trinh dien va ghi cac djnh dung

am thanh, hinh anh phe bien.
Surface manager: Quan ly hien thj nei dung 2D va 3D. Cho ph6p tvo cac ciza
so giao
OpenGL: HO trq xay dung ling clung de hqa 2D va 3D.
- SSL: Cung cap chile nang bao inOt cho fiat bi
SGL: Engine he trq M hqa 2D.
Free Type: HO trq cac Font Bitmap va vector
SQLite: Met co sir du lieu nhe gqn va mph me. Cung cep be may co s6 du
lieu duqc nhimg trong thiet bj.
Webkit: Ho trq hien thj nei dung website.

2.3.3. Android Runtime
He dieu hanh Android tich hqp sin met top hqp the thu vien cot 16i, cung cep
heu het cac chirc rang. Mqi ling dung ciut Android chay tren met tien trinh cua rieng
n6 cling v6i met the hien cim may ao Dalvik. May ao Dalvik thuc to la met bien the
dm may ao Java duqc sira Mi, be sung cac cling nghe dOc tnrng cim thiet bi di Mug.
NO duqc xay dung veri intic dich lam cho cac thiet bj di (king c6 the chay nhieu may k
met cach hieu qua.
Tnrem khi chay, mei ling dung Android deli duqc convert thanh file thuc thi Arai
QM dm nen Dalvik Executable (.dex). Dinh long nay duqc thiet ke de phi hqp veri

12


cac thiet bj han the ve b0 :the sung nhu toe do xi 1), . Ngoai chic flan ke tren, may lo
Dalvik cem sir dung b0 nhan Linux de cung cap cac tinh rang nhu thread, low-level
memory management.
2.3.4. Application Framework
Tang nay cia hg dieu hanh Android cung cap mot nen tang phat trien img dung
ma qua (16 cho phep cac lap trinh vien, cac nha phat trien img dung ci kha fling tao ra

cac img dung vo cling sang tao va phong phi. Cac rata phat trien (mg dung duqc to do
sir dung cac tinh nang cao cap ctla diet bj phan cing nhu: thong tin dinh vj dia 1ST, kha
nang chay djch vu cluth ne'n, thiet lip dOng h0 bao thic, them notification vao status
bar cia man hinh thiet
Ngubi phat trien img dung duqc phdp sir dung day di b0 API duqc dimg tong
cac img dung Itch hqp sin cia Android. Kien trim img dung cia Android duqc thiet ke
nham muc dich don gian h6a viec tai sir dung cac thanh phan. Qua d6 bat Id (mg dung
nao ding ci the cong b6 cac tinh thing ma ne mu6n chia se cho cac img dung khac
(VD: Ong dung email c6 muon cac img dung khac c6 the sir dung tinh ring gin mail
cia n6). Phucmg phap tucmg to cho phep cac thanh phan co the duqc thay the ben
ngubi sir dung.
Tang nay bao g6m met top cac services va fininh phan sau:
- View System: Ding de xay dung img dung c6 cac d6i ttrqng giao dien nhu
list, grid, texbox, button... hay ci the thing met trinh duyen web vio irng
dung.
- Content Provider: Cho phep cac img dung c6 the truy xuAt do lieu tar the *rig
dung khic hoc chia se der lieu giera ching.
- Resource Manager: Cung cap kha ring truy 'mat cac tai nguyen nhu hinh
anh hoac file giao dien (Layout).
- Notification Manager: Cung cap Idyl tiling hien thj thong bio tren thanh trang
thiti (Status bar).
- Activity Manager: Day la thanh plan quart trqng nhat, n6 giip img dung
quitn ly Ong dbi cia met Activity.
- Telephony Manager: Cung cap thu vien de truy neat den cac djch vu dien
thoai hay thong tin thug bao cia ngubi ding.
- Location Manager: Cung cap thu vien h6 trq ngubi ding dinh vj this& bj dua
tren GPS hoac mpg Ichong day witY3G.

13



2.3.5. Application
Tang nay chinh la tang china cac img dung duct phut trien boi !Op trinh vi'en, the
nha phut trien phan mem. Ngoai met s6 img clung duqc Android tich hqp s&n nhu
email, SMS, trinh duyet web, danh ba... thi ngiteri dimg c6 the de dung cai dOt them
cac Ung dung tin Google Play hay cac chq Ung di,mg Ichac.
2.4. ling dyng tren that b$ Android
2.4.1. Nhfing gldi hgn crra thiit 14 di ding
Mk di' cac thiet bj di dung thong minh c6 the thuc hien nhnng chin Ming tucmg
to nhu met chiec may tinh nhu chay da nhiem, xis 19 de hqa... Nhung thuc chat de van
la met thiet N vOi be nher va pin c6 hon. Ta c6 the dtly mph hieu suet hour dung cue
thiet bj len, tuy [Alien dieu de loi clang nghia vOi viec tieu Mn nhieu dien nAng va tai
nguyen ham, lam gilan then gian sir dung thiet N. Chinh vi the, khfic veri trinh img
dung tren may tinh thong thueng, Mil viet ling dung tren thiet bj di &Ong to can chi' 9
den nhUng gied hen sau:
- Kha rang xir 19, c6 hart
- BO nher co hon
- Pin co gieri hon
- Nen tang hg dieu hanh lchac nhau
- Thanh phAn phan cling khac nhau
- Kich thuerc man hinh nho
- Giao dien don gian
- Bang thong mpg c6 gi6i lion (3G, GPRS)
- Ket n61 mang Ichong 6n djnh.
2.4.2. Ngen ngit 41p trinh
trinh chinh thlic cue Android la Java. Mk du cat img dung tren
NgAn
Android duqc vitt bang nein agar Java, tuy nhien ban than Android lui !cluing the chay
duqc cac t$p tin Java c6 dung .jar. Ngen ner Java sir dung trong Android khong phai
la town be thu vier J2EE (Java 2 Platform, Enterprise Editiion) ma chi la met pit nho

de xay dung nun may ao Dalvik. Din tren may ao Java cila Sun, Google dA tinh chinh
va phut trien nen may ao Dalvik de bien djch cac top tin Java veri Mc de nhanh hon va
nhe hon. Den phien ban Froyo 2.2, Android dA ha My Just-in-time Compiler (JIT) lam
tang the de bien djch Java len tir 2 den 5 lin.

14


2.4.3. Mei Irtreng ltlp trinh
JDK: JDK la m6i tru&ng clung di vitt the Ong dung Java. MOt 130 JDK gOm
c6 JRE (Java Runtime Enviroment) va cac ding cp bien djch (javac), trinh
thuc thi (Java), gb loi, cac thu vien, be gia lap dien thoai...
Eclipse: Mei trtreng lap trinh chinh that cita Android la Eclipse yeti su hO trq
cita Plugin ADT (Android Development Tool). Ngu&i lap trinh c6 the de clang
tai 1)0 cong Gist nay tren trang chit cita Google. Met so thinh phAn caa ADT:
✓ Da (Dalvik Cross-Assembler): C6 chirc nAng chuyen dOi cac 16p Java a
duqc bien djch thanh met file nhj phan (.dex) de chay tren may io Dalvik
✓ Aapt (Android Asset Packing Tool): CO chirc thing doing g6i cac tap tin
.dex thanh tap tin .apk de ngutri ding c6 the cai det tren thiet bj di dOng
✓ Adb (Android Debug Bridge): Day la met au nOi de chuyin va cai dat
img dung len trinh gia lap (Emulator) hoac tren thiet bj Android that. Thiet
bj Android phai duce bat USB Debugging.
✓ Ddms (Dalvik Debug Monitor Service): Cung cap met so Bich vu nhu
quan 1$, thong tin tien trinh va nem xep, logcat...

15


CHISCING 3. TONG QUAN VE GOOGLE MAP API
3.1. Gi6i thieu ve Google Map API

Veri Google Map Android API, ban c6 the de clang dua ban de coa Google vao
trong Ong dung ciut minh. API se Air dOng xir ly vie'c truy cep den Google Map server,
tai a lieu, hien thi ban d6 va phan hei the tic dung. Ban cling c6 the sir dung cac ham
cisa API de them cac markers, cac hinh khei, cac lop phi( vio ban de co ban, va ban
cling c6 the tao met g6c (thin ban d6 rieng. Nhung doi Wong (16 cung cap cac thong tin
mer rung cho dia diem, giiip ngueri dimg c6 the giao tiep veri ban de. API cho phep
ngtren thing c6 the dua them cac thanh phen sau vio ban de:

Bieu tugng de &nit deu met vi tri cv the (Marker)
Tap cac (loan thing (Polylines)
Tap cac hInh hgc (Polygons)
Bieu tugng do hem de &nit dau mOt diem ten ban de' (Ground overlays)
tieu de cim ban (16 (Tile overlays)
Be cac hlnh anh duce hien thi tren
3.2. Sir dyng Google Map API
3.2.1. ai dtlt va cacti hiy Google Map API

3.2.1.1. Cai cidt
- Tren thanh Menu: Window > Android SDK Manager
Ede Edit ReNtbiii Seine EtaiNdte SW& Eidied

ENO

bin

Navatindow
New Rotor
Fide Toolbar
open Pespedive


a Client
a 90091etieY-seiviceta
a MeinActivity

Nat View



Customize Perspective—

D J Sever

Save Respective AsReset Respective—
Dose Respective
Close AI Respective;
Navirion

Android Virtue! Device Mango

a

Rom Android Lint
Preferences

Binh 3-1: Android SDK Manager

16





- Tick vi o Google API cho phien ban Android muiin &mg de to irng clang:
a
Tools

Packages

SDK Path: EASTUDV1Androidbdt-bundle-windows-3d36 64-2013052Asdk
Packages
*

API

Name
1, Android SDK Platform-tools
❑ , Android SOK Build-tools
7' Android SDK Build-tools

■1

;

So mp les f or SOK

n I. ARM EA81v7a System Image
Milt Gavle AM
n is Sources forAndmid SDK

4


■ Ea Android 422 (API 17)
■ Ili SDK Platform

0 i Samples *SDK
11 MI ARM EABI Oa System Image

slat

n Updates/New g Installed

Sort byes COAP1 level

()Repository

A

Status

17

S. Update available rev. 18

78

n Not installed

17

• 2 ea Android 4,3 (API 111)
p li Documentation *Android SDK

2* SOK Piatfam
EI

Rev.

15 Installed

18
18
18
18
18
18

1
1
1
1
1
7

0 Not installed
n Nat installed
in Not installed
fl n Not installed
rj Not installed
I n Not installed

17


2

0 Installed

17

1

0 Not installed

17

2

II Installed

0 Obsolete Select bla or

*

ladssal

it

I

Instant padragas—

I


Delete 5 pncbges—

I

Done loadng packages.

Binh 3-2: Cal * Google API

- Ka° tiep xueng duUi caa dank sich, chon Google Play services vu click vio
nut Install 2 package

17


4

Packages Tools
SDK Pads E15TUDY1Androithadt-bundlewindows-x86_64-201305221sdk
Packages
API

a Name
Ola Android SuppatKepasitaryl
Android Support Library
0 a GocgleAdMob Ads SDK

2

a


DO Googfe Anolytics App Docking SDK
Peprecoted] Gaogk Claud Messaging jar Andrei

on
rr a Google Play services
■ a Gawk Repository
Googfe Play APK Dominion Library
Da
❑ a Google A/ayBilling library
■ 0 Goalie Play Licensing Library
ga Goers US8 Diner
■ a Googk Web Driver
Da MM id EmulatorAcceleoror (NAX/4)
Show.

Stabs
= Nat installed

13

a Update available rev. 18

11
3
3

= Nat instoded
= Not installed
-.
.

_ . Nat installed

7

a Update available rev. 9

1
3
4
2

— Not instead
_
— Nat installed
..
Nat installed
= Not installed

7

a Update available rev. 8

2
3

= Not installed
7-1 Not installed
v

❑ Obsolete Select asay °clads*


Updates/New IZI Instalkd

Sort by: a API level

Rev.

0 Reposlary

wee

F

I

Install 11 pedlars—

I

Delete 5 pedants—

I

0 tit

Done looting packsges.

Rink 3-3: Cdl Google API (dip)

- Accept and install.

- Sau khi cal dilt, import project thu vier vao tong Workspace: Click File >
Import

Rink 3-4: Import

18

mu wee.


- Ch6n Android > Existing Android Code into Workspace

Select

Sled an import source
type filter text
0

a General

• 123 Android

ItS bitting Android Code Into Workspace
I, a cic..
0

(a, Git

D


Install

r,

Run/Debug

t,

Team

p

XML

0

Finish

< Back

Ifinh 3-5: Import dm Wen (tiip)

- Click Browse > CM den thu mvc chlra project thu vien google play services:
<Thu mvc china android sdk>/extras/google/google_play_servicesilibProject/googleplay-services_lib, va click Finish
3.2.1.2. ay Google API Key
De hien thi ban de, debug tre'n may that thi can c6 Google API key. De lay duge
Google API key thi an sir citing chung nhOn SHA1 (1 chuld Icy tv).
Chit Y: Vei project khic nhau thi can c6 key khic nhau.
a. Lay SHAT
- Ma command line, cd vio thu mvc cai Java Development Kit: CAProgram

Files\Java\jre7 \ bin

19


Nhap lenh Keytool -list -v -keystore <your keystore name> -alias
androiddebugkey. Viii <you keystore name> la dubng clan ley tin Eclipse nhu
sau: Windows > Preferences > Android > Build > Copy clang Default debug
keystore.
Nhap password la android, Enter > Hien thi ra SHAI. Copy SHA1

a six dung

cho buoy b.
b. Lay google api key
Vao Hang nhap bang tai khoan Google.
- Chbn Create Project.
- Ka° ming duet Click vao Google Maps Android API v2 de chuyen trang
thai sang On
An Google Contacts Car IDAV API

• S off

It Google Maps Android API v2



MCI
on




Google Maps API v2

Courtesy limit 10,000 requests/day

Courtesy emit_ 25.000 requests/day • Prima

Ifinh 3-6: Bet Google Maps Android API v2

- Click API Access > Create New Android Key
API Access

To wont Was, Goode playa inn en API tamest& Using a veld Oka Sum or API by den you to exceed
Authorized PP Amin
CIAO PO Soo owe to Van speck die as you par exarage.
contact rata whit Moly their usememes. osseum/s. and SW
inhumane mote A tope poem may contain up to 20 on Os

Lowman

Sagas API Mona
Use API frays le IS yoke papa who you do nol need te oxen tar SW Lemma
Key for Andrea amok Oa soakage')
AlzaSyk23011Thal009T1_70C10,3graC Ku}
API bay.
Android ANSI

All:36:00:70:3C:43:09:21:33:30:Atin zECi DO :11:12 fr:R2


Activated en

Ian, 13, 2013327

Aclestad by:

tonowmpionaamelsom - you

:al: cos

AM

Kay kr browser appe OS tekrea
aisestrookumsnorrowskut VOCKII7SICLIb•
AF1 key
Any saw alond
Ragan.
AMOS on: May 13, Ma 32e AM
torrnmatantaynalsem - you
MIMS Of

GY M Kerrie toy.- aaggeonniseet lard.,1 GSM sprarMagid tak..I Oule gas tea gwy_. I

Mink 3-7: Tgo API key

20


. >
- Dan SHA I dA thy dirge to (a) va them package img dung cua mink vio cu &

click Create.
Configure Android Key for bando
This key can be deployed In your Android applications.

API requests are sent directly to Googie from your clients' Android devices. Google verifies that each
request originates from an Android application that matches one of the certificate SHA1 fingerprints
and package names listed below. You can discover the SHM fingerprint of your developer certificate
using the following command:
keytool

-

list

-

v

-

keystone aystare. keystore Imam=

Accept requests from an Android application vdth ens of the certificate fingerprints
and package names listed below
45:85:E4:6F:36:AD:A:98:84:64:02:66:23:12:17:F2:56:26:A0:E 0 ;c0m.examplel

One SHAT certificate fingerprint and package name (separated by a semicolon) per line. Example:
45:B5:E4:6F:36:AD:OA:98:94:134:02:66:28:12:17:F2: 56 : 26 :A0 :£ 0 :com.example

SandiCanagl


Rink 34: Tpo API Key 2

- API hien ra, copy de dung cho viec lop trinh img dyng cita mirth
Simple API Man
Use API keys to identify your project when you do not need to access user data. Learn more
Key for Android apps (with certificates)
API key.
Android apps:

A6:36:COOD:SC:6E:89:21:99:1113:A9:6E:EC:D8:11:F2: 4 F:B2 : 11"4 : 81 ;coa

Activated on:

May 13, 2013 3:27 AM

Activated by.

tuantrungphamilagmadcom - you

Key for browser apps (with referers)
AltaSyDrtIclAYillitikvOk3jhz VdqgliE7S/Cd3hw
API key.
Referers:

My referer allowed

Activated on:

May 13, 2013 326 AM


Activated by.

tuantrungphamatgrnall.com - you

On" glegSalikflY-.1

crenserf 8rOWII.1 WTI 'Pal new etadraid key.
Hink 3-9: TR API Key 3

21

Crelle neW PS

I


3.2.1.3. Tgo project Demo
- Tao Project mai nhu birth thubng. Nhung cht-m Compile with Google API

New Android Applicadon
The press 'com.esemple: is most as a pleceholder end should not be used

Apple:ton Wed Demobendo

1

Project Nemeth Demobendo
Pecker NamedevanspIndemobado


hfinimum Required SDKAIAPI & MSS 22 (Foyo)

Target MOO API 17: And/60142 (Idk Been)
Corn* YAM API ifs AndeiddigillyIkeel
API 16 Android 213 (Goverbread)
Themen Google APIs (Google Inc) (API 10)
API it Android

picellithe most recent
Choose a tweet API API 17: Android 42 (Idly Been)
version, or 'Mint writarininnprwourawnwswwwwitwareaw etas wmout reflection.

Net)

Blab 3-10: Too project mot

22

Finish

I owl I


- Them thu vien Google Services vim project: Click chu6t phai vao project vita
too > Properties > Android > Add > Chun project Google Services

[type filter tot
4 Resource
Android
Android Lint Preferences

Builders
lava Build Path
An Code Style
D lava Compier
D lava Editor
lavadoc Location
Project References
Refactoring History
Run/Debug Settings
Task Tags
Va6dation

Android
Project Build Target
Target Name
0 Android 2.3.3
❑ Goodie APS
❑ Android 4.0
En G40914 APS
❑ Android 4.22

Vendor
Android Open Source Project
Google Inc.
Android Open Source Project
Googk Inc.
Android Open Source Project

Plefonn


2.3.3
2.3.3
4.0
4.0
4.22

API L10
10
14
14
17

Linty
0 Is Leary
Project
Referake
-4kidt-bundle-wkdovas-a16
64-2—
google-plysenicasjth
sI

W

or

Hinh 3-11: Thing dm Wen vdo do

- NOi dung cac file rib" sau:
- File layout: activity_main.xml.
<fragment xmlns:android=" />android:id="@+id/map"

android:layout_width="match_parent"
androitlayout height="match_parent"
class="com.google.android.gms.maps.SupportMapFragmentT>
- File AndroidManifest:
✓ Sir dung Google Maps thi can c6 intemet non can lchai boo quyen sir dung
intemet:
<uses-permission androitname="androidpermission.INTERNErn>

✓ Them permission de duc dit lieu ciia Google Services:
"com.google.androidproviders.gstpermission.READ_GSERVICEST>

23


✓ Ve ban dO bang Opengles 2.0
android: glEsVersion="0x00020000"
android: required="true" t>


Trong the Application can khai bao them meta-data de dua key dA lay

android: name ="com.google.artdroidmaps.v2.API KEY"
android:value="AlzaSyBFsTCparvGBvoH4qUE58g8hEgIVWOod 9RIC/>

- MainActivity extends FragmentActivity.
- Choy this, hien thi ban dO la thanh ding.
3.3. Clic 86i tuvng quan trong trong Google Map API


3.3.1. Doi tsryng bdn do The Map Object
Google Map Android API cho phep ngtaii ding c6 the hien thj ban cth cua
Google trong ling dyng Android. Ban M nay c6 giao dien giOng voi ban M chuin cua
Google. Tuy nhien van co met só diem khac biet nhu sau:
-

- DO lieu dia ban dO duqc hien thj bang API se khong c6 thong tin a nhan cua
nguti climg
- Khong phai bleu arcing nao tren ban a ding c6 the bam vao duqc. Tuy ninon
ta c6 the then cac Marker vao ban dO, API cho phdp ta co the thy chink duqc
giao dien ding nhtr phan hOi khi bim vao Marker.
Nhang ding viec sau duqc GoogleMap xir 19 tv dOng:
- Ket not den djch vv GoogleMap
- Tai xuting aft lieu ban dO
- Hien thj tren man hinh cua thiet b1 di dOng
- Hien thj cac nut de lieu Ichien ban a
- Phan hOi thao tac dia ngubi dimg nhu xoay hay thu phOng ban dO.
3.3.2. Marker

Marker la met d6i Wong quan tong va duqc sir dung rat nhieu trong ban dO. MOt
Marker &Id dien cho met vi tri cg the tren ban d6. Ngoai ra, ngubi lap trinh c6 the thy
bien Marker theo nhieu each ;chic nhau nhtr thay d6i bieu tuqng, mau sic, sv

24


3.3.2.1. Them mOt Marker
Sau day la dog' code vi du ye viec chen met marker vao ban do. Marker co toa
de a vj tri (0,0) ve hien thj deng chit "Xin chao" trong cfra s6 thong tin (Info Window):

private GoogleMap mMap;
mMap = ((MapFragment) getFragmentManager0.findFragmentByld(R.idmap)).gelMaPO;
mMap.addMarker(new MarkerOptionsO
.position(new LatLng(0, 0))
.title("Xin chao"));

3.3.2.2. My biin Marker
Marker co the duqc tity bien theo nhieu cich Ichac nhau, vi du nhu thay dei bieu
tuqng hay each Marker phan heti lai thao tic cea ngubi &mg.
Marker co the duqc tey hien cac thuOc unit sau:
a. Position (Vi tri)
Gia trj ctia dei tuqng Laing se xac djnh vj tri ctia Marker tren ban de. Day la gia
tri bat buOc phai dua vao khi chen Marker
b. Anchor
vao so vai gia tri cfla Lating. Vi tri mic

Diem ma bieu ttrqng Marker se duce
djnh lab gifta pit dugi cia bieu tucmg.
c. Title (Tieu de)

Day la tieu de cia Marker, khi ngubi dimg ba
tin hi'en len kern theo tieu de.



vao marker se co cua

so thong

d. Snippet

Deng chit be sung duqc hien thj b pit dual tieu de
e. Icon
Bieu ttrgng efts Marker dugc hien thj tren ban de.
f. Draggable
Gia trj true/false de cho phep hoic !thong cho phep Marker co the di chuyen tren
ban de
g. Visible
Gii trj true/false de cho phep hoic khOng cho phep Marker co the hien thj tree
ban cth

25


h. Float
Theo mac djnh thi Marker se duqc dat c6 djnh tren ban d6. Khi dat gia tri float
thanh true thl Marker se duqc xoay khi ta xoay ban dO, tuy !Mien kich thirdc cua
Marker se kh&ng bj thay dal
i. Rotation
DO xoay aim Marker theo chieu kim dling h6.
3.3.2.3. Thay ddi mau sdc Marker
Mau sac dm Marker c6 the duqc thay dai bang each sir dung dai tuqng
BitmapDescription khi d¢t gia tri icon:
BitmapDescriptorFactory.defaultMarker(float hue)

Gia tri dm hue nam trong khoang 0 den 360, d3i dien cho met vi tri trong yang
trim mau sic.
stalk final LatLng ABC = new LatLng(-37.81319, 144.96298);
Marker melbourne = mMap.addMarker(new MarkerOptionsO
.position(ABC)
.icon(BitmapDescriptorFactory.defaultMcrrker(BitsnapDescriptorFactory.HUE AZURE)));


3.3.2.4. Thay ddi blaze turmg Marker
Ngoai thay d6i mau sic, ta hoen than c6 the thay d6i bleu tuqng cim Marker.
Bieu tircmg thy chip luon duqc dat thkili mat di turyng BitmapDescription bang each
sir dung met trong bon plurcmg thirc cua doi tuqng BitmapDescriptionFactory:
- fromAsset(String assetName): sit clung mat anh trong thy myc asset
- fromBitmap (Bitmap image): sir dung mat anh Bitmap
- fromFile (String path): sii dung mat anh trong mat during den cy thi
- fromResource (int resourceld): stt dung mat tai nguyen caa churmg trinh
Sau day la vi du viec Lao Marker ved bleu tam dat trong drawable:
private static final LatLng HANOI = new LatLng(0,0);
private Marker melbourne = mMap.addMarker(new MarkerOptionsO
position(HANOD
litlerHANOI '9
.snippetrPopulation: 4,137,400'9
icon(BihnapDescriptorFactoryfromResource(R.drawable.arrow)));

3.3.2.5. Sy. ben nia Marker
Map API cho phep ngued I p trinh c6 the ling nghe v3 phan hai su kien cua mot
Marker. DE c6 the lung nghe su kien nay, ngubi lap trinh can phai cai dat listener
arcing (mg tr d6i tuqng GoogleMap china marker do.
Ngueli lap trinh c6 the xir Iy cac su kien sau:
- Sr kien barn vio marker

26


- Sr kien keo tha marker
- Scr kien barn vao InfoWindow
a. Su ki4n barn vac, marker

Nguei lap trinh c6 the sir dung OnMarkerClicIcListener de tang nghe sv kien khi
marker duqc barn vao. De cal at Listener cho ban da, ta can gqi *rang thirc:
GoogleMap.setOnMarkerClickListener(OnMarkerClickListener)
Khi ngutti dimg barn vao Marker, pinning thirc onMarkerClick(Marker) se duqc
gqi va marker se duqc truyen vao nhu mOt tham s6. Phuong that nay tra ve melt gia trj
boolean Neu thj viec da bat duqc mOt scr kien. Neu tra ve gia trj False, thi hanh dOng
mac djnh se dirge thifc thi cimg yen hanh dOng dA duqc tiny bien. Hanh dOng mac djnh
chinh la viec hien thj len Infowindow va di chuyen Camera den vj tri marker duqc
barn vao.
b. Sir kien keo tha Marker
Skr kien keo tha Marker duqc cal dot bang phuong thin OnMarkerDragListener.
De cai dot listener cho ban dO, ta can gqi phuong thuc:
GoogleMap.setOnMarkerDragListener

De keo tha Marker, ngutri dung can than va gift vao marker sau d6 di chuyen,
khi tha thay ra thl marker ttrcmg Ong se dugc dot vao vj tri meri. Khi marker duqc keo
di, onMarkerDragStart(Marker) se duqc gqi ngay lap tire. Khi marker dang di chuyen,
pinning thirc onMarkerDrag(Marker) dirge gqi, khi ket thlic keo tha phuong thirc
onMarkerDragEnd(Marker) duqc gqi. Ta c6 the lay ra tqa dO cila marker d6 bat ca lac
nio bang each gqi ham Marker.getPositionO.
3.3.3. Info Windows
Info Windows la mOt elm s6 !the) di kem vii marker. Cfra s6 nay se dugc bat len
khi ngueri clUng barn vao Marker. Info Windows mac djnh se hiO'n thi hai ding la Title
va deng snippet 6 phia du6i. Tai mOt thai diem chi c6 mOt Info Window dugc bat len.
Khi ngutti dung barn vao marker khic, info windows hien hanh se dugc An di va info
windows mei se duqc hien len.
3.3.3.1. Info Window rnek djnh
Cach don gian nhat IA dot gia trj cho Title va Snippet ctia marker, khi gia trj nay
doge dot thi Infowindows mac djnh se dirge bat len khi marker dugc ham vao
statkfinal LatLng DEMO = new LatLng(-37.81319, 144.96298);

Marker melbourne = mMap.addMarker(new MarkerOptionsO
.position(DEMO)
.titlerDemo Title")
.snippet("Demo Snippet");

27


×