Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
nacatl_slide_02_MapView_in_Recycler_view.pdf
Search
nacatl
March 18, 2019
370
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.3k
Navigation Componentを実戦投入した際の感動、便利さ、そしてつまづき
nacatl
0
3.2k
nacatl_slide_04_AAC_Navigation_Toolbar
nacatl
0
840
nacatl_slide_03_AAC_Navigation_SafeArfgs.pdf
nacatl
0
95
DynamicLinks 知られざる?Firebaseの秘技
nacatl
2
1.4k
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
300
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
エンジニアに許された特別な時間の終わり
watany
109
250k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
270
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
410
The Cost Of JavaScript in 2023
addyosmani
55
10k
The Curious Case for Waylosing
cassininazir
1
550
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
ご静聴ありがとうございました