Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
nacatl_slide_02_MapView_in_Recycler_view.pdf
Search
nacatl
March 18, 2019
350
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
nacatl_slide_02_MapView_in_Recycler_view.pdf
nacatl
March 18, 2019
More Decks by nacatl
See All by nacatl
Flutterにおけるアプリ内課金実装 -Android/iOS完全なる統一 -
nacatl
2
8.2k
Navigation Componentを実戦投入した際の感動、便利さ、そしてつまづき
nacatl
0
3.1k
nacatl_slide_04_AAC_Navigation_Toolbar
nacatl
0
830
nacatl_slide_03_AAC_Navigation_SafeArfgs.pdf
nacatl
0
94
DynamicLinks 知られざる?Firebaseの秘技
nacatl
2
1.4k
Featured
See All Featured
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
220
Testing 201, or: Great Expectations
jmmastey
46
8.2k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
150
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
260
Discover your Explorer Soul
emna__ayadi
2
1.2k
Typedesign – Prime Four
hannesfritz
42
3.1k
Designing for Timeless Needs
cassininazir
1
370
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
390
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
650
Making the Leap to Tech Lead
cromwellryan
135
10k
The Curse of the Amulet
leimatthew05
2
13k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
190
Transcript
Copyright 2018 Studyplus, Inc. All Rights Reserved. MapView in RecyclerView
つまずいた話 Yuzuru Nakashima / Studyplus Inc. 2019.03.18 @ Otemachi.apk #02
自己紹介 ✎ なかてぃる affinity_robots nacatl ✎ スタディプラスのAndroidエンジニア ✎ 趣味: Magic
the Gathering
目次 ✎ GoogleMapAPI ✎ したかったこと ✎ うまくいったこと ✎ つまずいたこと
GoogleMapPlatformAPI MapFragment? MapView?
GoogleMapPlatformAPI GoogleMapを表示するViewとFragmentを提供 - FragmentはLifeCycleの管理が楽(Viewだと面倒) - useViewLifecycleInFragment(true) - SupportLibrary版のSupportMapFragmentがある - LiteModeで表示すると単にbitmap表示するだけで軽い
- 開発チームはオーストラリア(余談)
したかったこと What is want to do?
したかったこと 大学のキャンパス一覧を RecyclerViewで実装したかった
したかったこと - 既存からのリファクタリング - 不要なカスタムビュー撤廃 - ButterKnife -> DataBinding -
Java -> Kotlin (つい最近Javaを超えた!!) - なんか突っかかる(UIスレッドで色々してる?) - MapView -> MapFragmentにしてLifeCycle処理任せる
うまくいったこと Success
うまくいったこと - 突っかかりの解消 カメラ位置の移動のために、GeoCoderを使って住所文字列から Map用のAddress クラスを取得する必要がある ここが遅いのにアイテム表示ごとにやってたから突っかかる -> Progress回しつつ初めに全アイテム分取得しておく RecyclerItemは住所文字列ではなくAddressを持つ
うまくいったこと RecyclerViewのサイクルに合わせた表示処理 - onCreateViewHolderでgetMap - onBindingViewHolderでmoveCamera - onViewRecycledでclear 参考: https://github.com/googlemaps/android-samples/blob/master/ApiDemos/java/app/s
rc/main/java/com/example/mapdemo/LiteListDemoActivity.java
うまくいったこと RecyclerViewのサイクルに合わせた表示処理 - onCreateViewHolderでgetMap override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)
= MapItemViewHolder(parent.inflate(viewType)).also { holder -> if (holder.binding is ListItemMapBinding) { holder.binding.campusMap.onCreate(null) holder.binding.campusMap.getMapAsync { map -> MapsInitializer.initialize(holder.itemView.context.applicationContext) mapType = GoogleMap.MAP_TYPE_NORMAL } } }
うまくいったこと RecyclerViewのサイクルに合わせた表示処理 - onBindViewHolderでmoveCamera override fun onBindViewHolder(holder: MapViewHolder, position: Int)
{ val mapListItem = getItem(position) holder.binding?.let { binding -> (binding as? ListItemMapBinding)?.let { holder.moveCamera(mapListItem.campusAddress) }
うまくいったこと RecyclerViewのサイクルに合わせた表示処理 - onViewRecycledでclear recyclerView.setRecyclerListener { holder -> if (holder
is MapViewHolder) { holder.releaseMap() } } fun releaseMap() { googleMap?.run { clear() mapType = GoogleMap.MAP_TYPE_NONE } }
つまずいたこと Missteps
最初の一個以外真っ白になった MAP つまずいたこと
つまずいたこと FragmentRecyclerViewと相性が悪いらしく、 結局MapViewにした… (公式サンプルでもViewだった…) 参考: https://stackoverflow.com/questions/50391459/supportmapfra gment-on-a-recyclerview
途中のアイテムが世界地図のままのことがある (視点位置が指定した場所に移動していない) つまずいたこと これ MAP MAP MAP
つまずいたこと RecyclerView内の表示準備不備が原因 - 表示にはMapクラスとAddressクラスが必要 - onCreateViewHolderでgetMapAsync - onBindViewHolderでitemの持つAddressにMapの カメラ位置を移動させたいが、まだ取得できてない onCreate
ViewHolder onBind ViewHolder (Address取得) 視点移動 したいのに Mapがない! Map取得! 時間(t) getMapAsync
MapとAddress両方をHolderでメンバ保持し、 どちらかが取れたタイミングで 視点移動処理を試す つまづいたこと onCreate ViewHolder onBind ViewHolder (Address取得) getMap
Async ItemのAddress 取得!可能なら 視点移動! Map取得! 可能なら 視点移動! 時間(t)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ~~ holder.binding.campusMap.getMapAsync {
map -> MapsInitializer.initialize(holder.itemView.context.applicationContext) holder.showMapIfAble(map) mapType = GoogleMap.MAP_TYPE_NORMAL } } } つまづいたこと
まとめ Result
- 公式サンプルはきちんと見よう - ViewのLifeCycleを気にしよう
https://info.studyplus.co.jp/recruit
ご静聴ありがとうございました