Pro Yearly is on sale from $80 to $50! »

Firestoreを利用したMAPアプリの開発について

68c380c9ce344f9e11d8a181d329426d?s=47 DaikiOKA
August 22, 2019

 Firestoreを利用したMAPアプリの開発について

68c380c9ce344f9e11d8a181d329426d?s=128

DaikiOKA

August 22, 2019
Tweet

Transcript

  1. Caraquri Tech Night #4 FirestoreΛར༻ͨ͠MAPΞϓϦͷ։ൃʹ͍ͭͯ גࣜձࣾZERO TO ONE Ԭ େو

  2. 5XJUUFS*% !OPSJOPSJ@PLB Ԭେو • ৽ଔͰZERO TO ONEʹೖࣾ͠ɺ nori-naʹδϣΠϯ͢Δɻ • ࣾձਓ̏೥໨ࣾ಺།ҰͷΞϓϦΤ

    ϯδχΞ • iOS(Objective-CɺSwift)ɺ Android(JavaɺKotlin)ɺWebͱ αʔόʔ(CakePHPɺTypeScript) Ͱ։ൃ ࣗݾ঺հ DBSBRVSJ5FDI/JHIU
  3. OPSJOBͱ͸ʁ ۭ੮ͷ͋ΔυϥΠόʔͱಉ͡ํ޲ʹҠಈ͍ͨ͠ਓΛ Ϛονϯάͤ͞Δ૬৐ΓʢϥΠυγΣΞʣαʔϏε DBSBRVSJ5FDI/JHIU

  4. ϏδωεϞσϧ ૬৐Γ୅ ۭ੮ Ҡಈ͍ͨ͠ υϥΠόʔ ख਺ྉ DBSBRVSJ5FDI/JHIU

  5. ΞϓϦͷྲྀΕ ໨త஍ ஍ਤɾ501 Ϛονϯά ϝοηʔδ DBSBRVSJ5FDI/JHIU

  6. ஍ਤը໘ͷઆ໌ ৽ண৘ใ ϥΠϒνϟοτ ৽ن࡞੒ ืूͷݕࡧ ۙ͘ͷϩάΠϯϢʔβʔΛ දࣔ ૬৐ΓͷϦΫΤετΛૹ৴ DBSBRVSJ5FDI/JHIU

  7.   OPSJOB 'JSFTUPSF $MPVEGVODUJPOT GPSpSFCBTF όοΫΤϯυ 'JSFCBTF nori-naͷγεςϜߏ੒ ໰͍߹Θͤ

    DBSBRVSJ5FDI/JHIU
  8. ࠓ೔ͷ͓࿩   DBSBRVSJ5FDI/JHIU

  9. Ґஔ৘ใΛར༻ͨ͠ΞϓϦ͕ ૿Ճ܏޲   DBSBRVSJ5FDI/JHIU

  10. Ґஔ৘ใΛڞ༗͢Δ͜ͱʹ ఍߅ײ͕ͳ͘ͳ͖ͬͯͨ   ஍ਤར༻࣮ଶௐࠪcגࣜձࣾθϯϦϯ DBSBRVSJ5FDI/JHIU

  11. •έϞϯGO Z•nly Twit•er   DBSBRVSJ5FDI/JHIU

  12. چόʔδϣϯ ৽όʔδϣϯ ςΩετϕʔε Πϕϯτॏࢹ Ϛοϓϕʔε ϦΞϧλΠϜॏࢹ DBSBRVSJ5FDI/JHIU

  13. ͳͥม͑ͨͷ͔   DBSBRVSJ5FDI/JHIU

  14. چόʔδϣϯ ৽όʔδϣϯ ςΩετϕʔε Πϕϯτॏࢹ Ϛοϓϕʔε ϦΞϧλΠϜॏࢹ DBSBRVSJ5FDI/JHIU

  15. ωΠςΟϒͷҙຯͳ͍   DBSBRVSJ5FDI/JHIU

  16. MAPͰϦΞϧλΠϜʹ૬৐Γ   DBSBRVSJ5FDI/JHIU

  17. MAPϝΠϯͰؾ͍ͮͨ͜ͱ   DBSBRVSJ5FDI/JHIU

  18. Ϣʔβʔͷ཭୤཰͕௿͍   DBSBRVSJ5FDI/JHIU

  19. Ұिؒޙͷ཭୤཰ چόʔδϣϯ 10~15% ৽όʔδϣϯ 20~35% ଟ͍࣌50%   DBSBRVSJ5FDI/JHIU

  20. ͳͥ   DBSBRVSJ5FDI/JHIU

  21. ϢʔβʔͷϦΞϧλΠϜͳಈ͖͕ ݟΕΔ͔Β   DBSBRVSJ5FDI/JHIU

  22. ஌Βͳ͍ਓͰ΋࣮ࡍʹډΔͱ ҆৺͢Δ   DBSBRVSJ5FDI/JHIU

  23. FirebaseͷϦΞϧλΠϜੑΛ׆༻ • FirestoreΛར༻ • ΞΫςΟϒͳϢʔβʔҎ֎Λ ൒ಁ໌ • දࣔͯ͠ಈ͍͍ͯΔϢʔβʔ ͷಈ͖Λ௥͏ •

    Ͳͷ͘Β͍લʹىಈͨ͠ͷ͔ Θ͔Δ
  24. • FirestoreΛར༻ • ΞΫςΟϒͳϢʔβʔҎ֎Λ ൒ಁ໌ • දࣔͯ͠ಈ͍͍ͯΔϢʔβʔ ͷಈ͖Λ௥͏ • Ͳͷ͘Β͍લʹىಈͨ͠ͷ͔

    Θ͔Δ FirebaseͷϦΞϧλΠϜੑΛ׆༻
  25. ࢖༻ͨ͠MAP .BQ,JU (PPHMF.BQ ਌࿨ੑ σϑΥϧτ αʔυύʔςΟʔ ྉۚ ແྉ ैྔ੍ ܦ࿏දࣔ

    ͋Γ ͳ͠ ϝϞϦ গͳ͍ ଟ͍ MapKitͷศརͳ఺ ɾٯGeocodingɿҢ౓ܦ౓͔ΒॅॴΛऔಘՄೳ GoogleMapͷศརͳ఺ ɾετϦʔτϏϡʔ ɾ༗໊ͳ؍ޫ஍ͷ৘ใΛදࣔՄೳ DBSBRVSJ5FDI/JHIU
  26. ϢʔβʔͷҐஔ৘ใ Firestore্ͷҰͭͷҐஔ৘ใΛߋ৽͠ଓ͚Δ →উखʹߋ৽ →ϦΞϧλΠϜͰϢʔβʔ͕ಈ͘ DBSBRVSJ5FDI/JHIU

  27. ໰୊఺   DBSBRVSJ5FDI/JHIU

  28. ಈ࡞͕ॏ͘ͳΔ   DBSBRVSJ5FDI/JHIU

  29. ಈ࡞͕ॏ͘ͳΔݪҼ ঢ়گ දࣔ͢ΔϢʔβʔ͕ଟ͗͢Δʢ͓Αͦ300 ϢʔβʔΛ௒͑Δʣͱը໘͕ఀࢭ͍ͯ͠ ͨɻ ݪҼ ΞΠίϯը૾ͷαΠζ੍ݶΛ͔͚͍ͯͳ ͔ͬͨͨΊɺը૾ʹΑͬͯ͸ಡΈࠐΈʹ࣌ ͕͔͔ؒͬͨ

  30. ຖճϢʔβʔΛಡΈࠐΉ JGMFUMBTU$FOUFS-PDBUJPOTFMGMBTU$FOUFS-P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 ɾΞοϓϩʔυ΋Cloud Functionͱಉ༷ ɾ΋ͪΖΜFirestoreͷ৘ใΛදࣔՄೳ ɾnori-naͰ͸Vue.jsͰ࡞੒ DBSBRVSJ5FDI/JHIU

  34. IUUQTTFBSDIOPSJOBKQ DBSBRVSJ5FDI/JHIU

  35. IUUQTTFBSDIOPSJOBKQ DBSBRVSJ5FDI/JHIU

  36. ͥͻ࢖ͬͯཉ͍͠ Cloud functions for Firebase

  37. Cloud functions for firebaseͱ͸ 'JSFCBTFͷϢʔβೝূɺσʔλϕʔεͷ௥ՃͳͲͷΠϕϯτ Λड͚औͬͯॲཧΛߦ͏αʔϏε ݴޠɿ+BWB4DSJQUPS5ZQF4DSJQU 'JSFTUPSFτϦΨʔ w PO$SFBUF

    w PO6QEBUF w PO%FMFUF w PO8SJUF DBSBRVSJ5FDI/JHIU
  38. nori-naͰͷར༻ํ๏ • ϓογϡ௨஌ • σʔλͷूܭ • ֎෦αʔϏεͱͷ࿈ܞ(ܾࡁɺݕࡧ) DBSBRVSJ5FDI/JHIU

  39. ϓογϡ௨஌ onCreate export const pushRideshareRequest = functions.firestore .document(commonUtil.makePath('ridesharerequest/{requestId}')) .onCreate((snap, context)

    => { const newValue = new firestoreModels.RideShareRequest(snap.data()); const to = newValue.to; console.log(`push start ridesharerequest : ${context.params.requestId}`); return pushMessageByUserId(to, '૬৐Γґཔ͕ಧ͖·ͨ͠ɻ಺༰Λ֬ೝͯ͠ڐՄ͠·͠ΐ͏ɻ'); }); DBSBRVSJ5FDI/JHIU
  40. ϓογϡ௨஌ onUpdate export const pushLikeComment = functions.firestore .document(commonUtil.makePath('mapcomment/{mapcommentId}')) .onUpdate((change, context)

    => { const afterData = new firestoreModels.MapComment(change.after.data()); const afterLike = afterData.likeMembers.length; const beforeData = new firestoreModels.MapComment(change.before.data()); const beforeLike = beforeData.likeMembers.length; const toUserId = afterData.user; if (!toUserId) return null; if (beforeLike < afterLike) { return pushMessageByUserId(toUserId, '͍͍Ͷ͕ԡ͞Ε·ͨ͠ʂ'); } return null; }); DBSBRVSJ5FDI/JHIU
  41. ϩʔΧϧͰςετՄೳ $npm run shell DBSBRVSJ5FDI/JHIU

  42. ςετίʔυ QVTI%FTUJOBUJPO6QEBUF  \ CFGPSF\ TDSFFO/BNFVTF  MPDBUJPO\ MBUJUVEF 

    MPOHJUVEF ^  EFTUJOBUJPO\ OBNF5  HFP-PDBUJPO\ MBUJUVEF  MPOHJUVEF ^ ^ ^  BGUFS\ TDSFFO/BNFVTFS  MPDBUJPO\ MBUJUVEF  MPOHJUVEF ^  EFTUJOBUJPO\ OBNF5PLZP5PXFS  HFP-PDBUJPO\ MBUJUVEF  MPOHJUVEF ^ ^ ^ ^  \ QBSBNT\ VTFS*EVTFS ^ ^  DBSBRVSJ5FDI/JHIU • beforeͱafterʹͦΕͧ ΕσʔλΛهड़ • params͸ඞཁͳ࣌ͷ Έ
  43. Cloud Functionͷ৽ػೳ Scheduler export const cronRemindShare = functions.pubsub //.schedule("0 18

    * * *")//ຖ೔18࣌ʹ࣮ߦ .schedule("every 5 minutes")//̑෼͓͖ .timeZone("Asia/Tokyo") .onRun(async context => { console.log("͜͜Ͱఆظ࣮ߦ") });
  44. ·ͱΊ Firebase+Map͸਌࿨ੑ͕ඇৗʹߴ͍ ϢʔβʔҐஔ৘ใΛϚοϓʹϦΞϧλΠϜදࣔ͢Δͱ݁ߏ໘ന͍ ͔ͦ͠͠ͷ··Ͱ͸ॲཧʹ໰୊ ରࡦ • දࣔ͢ΔൣғΛݶఆ • ଟ਺ͷϢʔβʔΛҰͭʹ·ͱΊΔ Webϖʔδ͸HostingͰ։ൃ͠Α͏

    DBSBRVSJ5FDI/JHIU
  45. ͋Γ͕ͱ͏͍͟͝·ͨ͠