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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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.1k
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
sira's awesome portfolio website redesign presentation
elsirapls
0
280
The Mindset for Success: Future Career Progression
greggifford
PRO
0
370
Odyssey Design
rkendrick25
PRO
2
710
RailsConf 2023
tenderlove
30
1.5k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
210
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
190
Making Projects Easy
brettharned
120
6.7k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
400
How to Ace a Technical Interview
jacobian
281
24k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
The agentic SEO stack - context over prompts
schlessera
0
820
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
ご静聴ありがとうございました