MVC LVC LEI NOI DAU 1 CH1TONG 1. GIO.1 THIU BAI TORN 3 1.1. VAI NET VE GOOGLEMAP 3 1.2. NNONo GI GOOGLEMAP KHONG HO TROT 3 1.3. Tim SAO LAI CAN ONG DUNG CHIA SE VI lid? 3 1.4. MOI THONG HOAT %NG 4 1.4.1. Tai sao lai ding Android? 4 1.4.2. Google Map API lagi? 4 1.4.3. Server gamin 11 , hoot dong 4 CH1UONG 2. GIOI THIU HE DIEU HANH ANDROID.. ..... 2.1. ANDROID LA GI? 5 2.2. LjCH Sll PRAT TRIEN 6 2.2.1. Su ra dei cia Android 6 2.22. Ctic phien ban Android 7 2.3. KEEN TROC HE DIEU HANH ANDROID 11 2.3.1. Linux Kernel 11 2.3.2. Libraries 12 2.3.3. Android Runtime 12 2.3.4. Application Framework 13 2.3.5. Application 14 2.4. fiNG DUNG THEN TIBET BI ANDROID 14 2.4.1. 1VhOng gidi hpn cua thilt bi di Ong 14 2.4.2. Ngen ng9 lop trinh 14 2.4.3. Most truing hgp trinh 15 CHUVNG 3. TONG QUAN VE GOOGLE MAP API —16 3.1. GICsi THIU VE GOOGLE MAP API 16 3.2. SO DUNG GOGGLE MAP API 16 3.2.1. cai d4t va arch ery Google Map API 16 3.3. CAC DOI WONG QUAN THONG WONG GOOGLE MAP API 24 13.1. tuong ben db The Map Object 24 3.3.2. Marker 24 13.3. Info Windows 27 CHITONG 4. CHHONG TRINH 2FRIEND ...29 4.1. GI Tilleu BA1 TOAN 29 4.2. MOT s0 flu cAu COA BA1 ToAN 30 4.3. CAc nitre NANG cHINN 31 4.3.1. Chic ming mg kyStai chain 32 4.3.2. Chtic :tong demo MO 36 4.13. Chic ming xem ban do 39 p 4.14. Chic ming xem vi tri mkt mink 42 4.15. Char ndng xem vi tri bon bi 46 4.3.6. Chile nang nip nh4t t4 tri 51 4.3. 7. Chtk mIng gui yiu cdu kit bon 53 4.3.8. Chic mkg xcic nIttrm yiu eau kit bon 57 4.3.9. Chtic ntIng tim ditimg din vi tri bon 61 4.3.10. Chile rating xem thong tin bon 63 4.3.11. Char ?tang giao tilp vol bon 66 4.112. Chic neng Miy kit bon. 69 4.3.13. Chic ming Op MO thong tin cli ?them 72 4.3.14. Chile :tang thay dal met khiu 76 4.3.15. Chic mIng (Yang mit 80 4.4. MQT SO VAN DE icHAc 82 4.4.1. Kin di chi duir• ng Direction API 82 4.4.2. Kin di dinh vi vi tri thiit bj 85 4.4.3. Kin di idn suit cdp nhtit de lieu 88 4.5. THIET KE cO set al LIEU 4.11. M6 hinh quan hf 89 4.5.2. Cac bang ate Nu 89 4.6. KET LUAN VA DINH WANG PHAT TRIEN 92 4.6.1. Kit qua dot or 92 4.6.2. Dinh Throng phcit Men 92 CH1UONG 5. PHU LOC CODE MQT So alit NANG CHINH• 94 5.1.1. Cher Wing deng kY tii khoint 94 5.11 Chtk ?tang ddng nhdp 95 5.1.3. Chic ming hien tri vi tri bon 96 5.1.4. Chile :tang gut yiu cdu kit km 97 5.1.5. Char ming xac nhtin yiu cdu kelt bon 98 5.1.6. Chtec Mug dinh vi vj tri 100 11.7. Char tiling tim dventg din vi tri 101 5.1.8. Chile ?tang cdp Mule thong tin ca thin 105 5.1.9. Char nang thay doi mot khtiu 108 TAI LIEU THAM CHAO 110
BQ MAO DUC DAO T30 D3I HQC THANG LONG -o0o - ICHOA LUAN TOT NGHIEP TIM HIEU NCH VI) GOOGLE MAP XAY DIJSNG ffNG DIJNG CHIA SE VI TRi VOI BAN BE TREN NEN TANG ANDROID MAO VIEN HUONG DAN : Ths Le Minh Tula SINN VIEN THVC EltN : Tan Trung MA SINK VIEN : A14986 CHUAN NGANH : Khoa hue may tinh HA NQI - 2014 MVC LVC LEI NOI DAU CH1TONG GIO.1 THI$U BAI TORN VAI NET VE GOOGLEMAP 1.1 1.2 NNONo GI GOOGLEMAP KHONG HO TROT Tim SAO LAI CAN ONG DUNG CHIA SE VI lid? 1.3 MOI THONG HOAT %NG 1.4 1.4.1 Tai lai ding Android? 1.4.2 Google Map API la gi? 1.4.3 Server gamin 11 , hoot dong -3 3 4 4 CH1U'ONG GIOI THI$U HE DIEU HANH ANDROID - ANDROID LA GI? 2.1 LjCH Sll PRAT TRIEN 2.2 2.2.1 Su dei cia Android 2.22 Ctic phien ban Android KEEN TROC HE DIEU HANH ANDROID 2.3 2.3.1 Linux Kernel 2.3.2 Libraries 2.3.3 Android Runtime 2.3.4 Application Framework 2.3.5 Application fiNG DUNG THEN TIBET BI ANDROID 2.4 2.4.1 1VhOng gidi hpn cua thilt bi di Ong 2.4.2 Ngen ng9 lop trinh 2.4.3 Most truing hgp trinh CHUVNG TONG QUAN VE GOOGLE MAP API GICsi THI$U VE GOOGLE MAP API SO' DUNG GOGGLE MAP API 3.2 3.2.1 cai d4t va arch ery Google Map API 3.3 CAC DOI WONG QUAN THONG WONG GOOGLE MAP API 3.1 tuong ben db - The Map Object 13.1 3.3.2 Marker 13.3 !Info Windows CHITONG CHHONG TRINH 2FRIEND 6 11 11 12 12 13 14 14 14 14 15 —16 16 16 16 24 24 24 27 29 4.1 GI& Tilleu BA1 TOAN 29 4.2 MOT s0 flu cAu COA BA1 ToAN CAc nitre NANG cHINN 30 31 4.3 4.3.1 Chic ming &mg kyStai !chain 4.3.2 Chtic :tong demo MO 4.13 Chic ming xem ban 32 36 39 p Chic ming xem vi tri mkt mink 4.14 42 4.15 Char ndng xem vi tri bon bi 46 4.3.6 Chile nang nip nh4t t4 tri 51 4.3 Chtk mIng gui yiu cdu kit bon 4.3.8 Chic mkg xcic nIttrm yiu eau kit bon 53 4.3.9 Chtic ntIng tim ditimg din vi tri bon 61 57 4.3.10 Chile rating xem thong tin bon 63 4.3.11 Char ?tang giao tilp vol bon 66 4.112 Chic neng Miy kit bon 69 4.3.13 Chic ming Op MO thong tin cli ?them 72 4.3.14 Chile :tang thay dal met khiu 76 4.3.15 Chic mIng (Yang mit 80 MQT SO VAN DE icHAc 4.4 82 4.4.1 Kin di chi duir• ng - Direction API 82 4.4.2 Kin di dinh vi vi tri thiit bj 85 4.4.3 Kin di idn suit cdp nhtit de lieu 88 THIET KE cO set al LIEU 4.5 4.11 M6 hinh quan hf 4.5.2 Cac bang ate !Nu 4.6 KET LUAN VA DINH WANG PHAT TRIEN 4.6.1 Kit qua dot &or 4.6.2 Dinh Throng phcit Men CH1UONG PHU LOC - CODE MQT So alit NANG CHINH• 89 89 92 92 92 94 5.1.1 Cher Wing deng kY tii khoint 94 5.11 Chtk ?tang ddng nhdp 95 5.1.3 Chic ming hien tri vi tri bon 96 5.1.4 Chile :tang gut yiu cdu kit km 97 5.1.5 Char ming xac nhtin yiu cdu kelt bon 98 5.1.6 Chtec Mug dinh vi vj tri 100 11.7 Char tiling tim dventg din vi tri 101 5.1.8 Chile ?tang cdp Mule thong tin ca thin 105 5.1.9 Char nang thay doi mot khtiu 108 TAI LIEU THAM !CHAO 110 DANII MVC HITNH ANH Hinh 2-1: Cac phen cila he dieu himh Android 11 Hinh 2-2: M8 hinh hqp tac gifts may io Dalvik vi Native code 11 Hirsh 3-1: Android SDK Manager 16 Hinh 3-2: Cai det Google API 17 HInh 3-3: Cai Google API (tiep) 18 Hinh 3-4: Import thu vien 18 Hinh 3-5: Import thu vien (tiep) 19 HIM 3-6: Bet Google Maps Android API v2 20 Hinh 3-7: To API Key 20 Hin ► 3-8: Tao API Key 21 HIM 3-9: Tao API Key 21 Hinh 3-10: Tao project m6i 22 HInh 3-11: Them thu vien vio du an 23 H1nh 3-12: Infowindow thy Bien 28 HInh 4-1: Min hlnh kheri dOng 29 Hinh 4-2: Deng k, tai Ichoen med 35 Ifinh 4-3: Man hinh ding nhep 38 Hinh 4-4: Hien th1 ban de 41 HInh 4-5: Dinh v1 va hien th1 vi tri ngtrbi dung 45 Hinh 4-6: Xem vita ban be 50 Binh 4-7: Giri yeu eau ket ban 56 Minh 4-8: 'Chong the girl them yeu cku 56 Hinh 4-9: Xic nhen yeu ket ban 60 Hinh 4-10: Tim &Ong di den vj tri ban 62 Hinh 4-11: Xem thong tin ban 65 Binh 4-12: Giao tiep ved ban 68 Hinh 4-13: Hity kit ban (x6a ban) 71 Hinh 4-14: Cep fillet thong tin ca Mien 75 Hinh 4-15: Thay doi mat khan 79 Hinh 4-16: Dinh vi bang sling di dOng 86 DANH MVC BANG BLEU Bang 4-1: Cac each dinh vi vi tri 85 Bang 4-2: Bang Users 89 Bang 4-3: Bang Location 90 Bang 4-4: Bang Friendl 90 Bang 4-5: Bang Friend2 91 DANH MVC SO Del So de 4-1: So a Use - case 31 Sa 4-2: Ding ky tai lchoan 32 So di) 4-3: Trish tkr Ding ky tai khan 33 So 4-4: Ding Step 36 So 4-5: Xem ban 39 So d6 4-6: Xem vi tri cita minh 42 So 4-7: Trish tv Xem vi tri cita minh 43 So d6 4-8: Xem vi tri bon be 47 So 4-9: Trish tir Xem vi tri bon be 48 Scr 4-10: Giri yeu citu ket bon 54 So de 4-11: Xac nhe ► yeu cam ket bon 58 So 4-12: Giao flip veri bon 66 So de 4-13: Huy ket ban 69 Scr de 4-14: Thay doi thong tin ca nhhn 73 So de 4-15: Thay den met khau 77 So de 4-16: Ring xuat 80 So 4-17: Ma hinh der lieu quan he 89 Lin NOIMu Sau met thai gian hoc tap va tim hieu clued sq turemg dart cua cac thay ca, em dA hoan khOa Juan tot nghiep cua minh Em xin than gui led cam an den cac thay c8 giao b0 mon Tin hoc tru?mg Doi hoc ThAng Long dA huOng din va giOp der em qua With em hoc twang Em xin dac biet girl leri cam an den thay Le Minh Than dd htremg din em thuc hien Mt& luon bet nghiep Sau holm luan vim dm mink, em cam thay minh dA to tin han vai kien thi cda minh, nhien em cam thay minh vin can rat nhieu thieu s6t can phai hoc tap de bel sung kien thiic MOt lean nera em xin chin cam an cac thiy co QA giup der em suet qua trinh em hoc tap trutmg Doi hoc ThAng Long Trong cuOc sting hien doi nay, tong nghe phat trien math me gin') ngtrei clang thuc hien duqc Miring c8ng viec ma truerc day twang nhu rat kh6 Ichtin Sr phat trien cua phuong tien giao thong gitip chang ta di co the bay cao has, di xa has va nhanh ham Tut' ninon kid slat chin den met quec gia khac, met phO Idkic hay don gian chi la met phO lin du bon slat chin den, neu 'thong c6 ban da thi a viec tim dubng se kha kh6 Ichtin Thubng thi bon se phE vita di vira heti dubng, hoac tim met cira hang gin shat c6 ban ban Viec de cling Icha the vi, n6 se cho ban cam giac Icham pha met mien diet mai, nhien n6 cling ton Idd nhieu thbi gian quY bau dm bon, nhat la neu ban la doanh titan dang c6 c8ng viec quan tong D6 chinh la Mc ban can den su h8 trq ci5a Cling nghe thong tin CEng nghe th8ng tin dA phat trien het sirc mash me nherng Mtn gin day Ngay bon c6 the tre chuyen, chia se hInh anh vai nhOng ngutri bon, ngueri than gia dlnh Ichoang cach nua vemg trai slat hay xa ham nera, giteg nhu ban dang tr6 chuyen vai mot ngued a wit minh vay CO the nal ding nghe phi trien dA dem ngutri lei gin has KhOng chi c6 vay, cac chuang trinh ling dung dm dimg has Kh8ng can bit dean Cling nghe thong tin el, ngtred c6 cuOc sting vet s6 sach nhu truac, hien tat ca dA the luu tren may vi tinh veri met thiet bj luu ter vo cling nhet gm Han the 'Oa vai met s6 chuong trinh dit tien, chung ta duqc h8 trq ca viec hooch djnh phuang huerng phat trien cho doanh nghiep fly can a yen de di neu tren? Lieu CEng nghe th8ng tin c6 gulp gi thing ta tong viec tim dubng di lei den met not ma ta Ich8ng bier? KhOng phai Mc nao ta cling mang theo Laptop hay may vi fish, viec di chuyen you ciu ta mang theo thiet bj she gon D6 chinh la met ling ch,mg cfm chuong trinh ban tren thiet bj di dOng thong mirth Thiet bj di dOng thong mirth khong can qua xa lo vai chimg ta D6 chinh la Dien thoai th8ng mirth — Smartphone — hay may tinh bang — Tablet NhOng thiet bj di dOng de c6 kich thuerc cling nhu tong luqng rho han nhieu so vai mot chiec Laptop Giao dien de clang sir dung han, Chao tic bing cam Ong tien lqi han va khong phi thuec vito cac thiet bj di kern Ichac Han the ars, thief bj di Ong sir dung nen tang phi bien nhu Android, IOS sb hau met kho img dung kiting 16 Chic hin ban dang to hei ring vei kho img dung len nhir vay thl chic chin se c6 Stung img dkuig kern chat lugng, hay cen gqi la "rac", veay lam met ngued dung birth thtrbng c6 the phan biet duqc? Cau tra lbi la ban hay yen Lim ve chat Itrqng ciut kho Ong dung Android hay LOS Bei vi di c6 met (lei ngil uy tin giep to kiem duyet Ong dung truck duqc dua len kho Ong ch,mg chung Han the nem dii v6i met nen tang ce nhieu ngubi sir dung ban dm duqc h6 trq bei chinh nhibig ngtroi dimg truer de DO chinh la sue manh cea ceng ding ding ngh'e Tref lai ved yin de chink, ling dung nao glop db to tiet kiem thbi gian tong vies tim dubng? D6 chinh la CEng dung ban d6 tren diet bj di dung Hien met chiec dien thoai thong minh ma kh8ng ce chuang trinh ban d6 thi khe ce the gqi la "thong minh" Hoic vi met 19 nao Q6 nha sin xuit luqc bet img dung de, thi viec tien ngueri ding lam se tau met chiec dign thoai th8ng minh de la tai img dung ban d6 O phan sau t8i se de cap den met ling dung ban di rat phi bien, c6 the nOi la t6t Mat hien hay, de chinh la GoogleMap Chinh nhUng nhting 19 tren da tao Ong luc cho em tim hieu va xay dung img dung chia se vi tri tren nen tang Android sir dung ban di Google Map Chi tiet ye du an em se With bay b nhemg phlin sau Chuang 1: Geri thieu bai toan Chuang 2: Gioi thieu he dieu lulnh Android Chuang 3: Ting quan ve GoogleMap API Chuang 4: Chuang With 2Friend Chuang 5: Phu lye: Code met s6 chi= Ming chinh Tii lieu tham CHVONG 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 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 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 viec tim duang di 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 each 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 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 khac ma GoogleMap da dimg trq da la firth nang chia se vi tri vUi ban be, ngutri than(Google Latitude) Chinh dieu da thitc dAy ten xay dung mot (mg dung chia se vj tri ban be teen Google Map 1.3 Tai 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 thi dft lieu se khong the cOp nhOt thu?mg xuyen, trir moi khu ph6 tren the giei deu co than vien cita Google Chinh vi v$y thing ta co the S 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 ta chi mut% chia se yen ngutri than gia dinh, hay bon be ma then Con nhieu van de !chic nfta, nhung da chinh la ljf de WI xay dung chuong trinh 1.4 Mei truirng boat (long Chuang trinh 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 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 ChInh dieu da da &rip cho cac nhi sin xuAt clang hon tong viec cho nhUng sin pham het sirc da ding, gifip thiet bi di ding Android c6 s6 ngteri sir dyng kh6ng 16 Ben milt 46 gii 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 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 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 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 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 khong an quan tam server lam gi ma chi can thao tic tren thiet bj dm mirth CHUONG 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 Tuy nhien vao theri diem da Android van chug duct met Den aim 2007 Android mai mit cling yeti tuyen b6 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 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 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 Tinh den thed diem thing 10 niun 2012 — Titan sau 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 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 St; c8ng cim hg dieu hanh cling Man ne frac muc tieu 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.1.3 Quit niing hien tri tri ben private class updatefriendtask extends Asyncrask protected String dolnBackground(String urls) { if(cl!=null) if(username==null) username=mbundle.getStringruser); iffid==null) id=getid(username); friendlist=gerend(id); String() friends=kiendlist.splitr "); templatIng=new LatLng[(friends.length/3)]; friendinfo=new Stringl(friends.length/3)1; kiendmarker=new Markerlikiends.length/311; for(int i=0;i