Zoom to the closest level that still shows all markers, including the blue MyLocation marker

旧街凉风 提交于 2019-12-08 12:22:26

问题


I would like to zoom and position my GoogleMap such that all markers, including the blue MyLocation marker, are visible. This SO question shows how to do this for all manually added markers, but I am not sure how to get a handle to the MyLocation marker, which is automatically added after calling setMyLocationEnabled(true), in order to pass it to the LatLngBounds.Builder.

I have tried using GoogleMap.getMyLocation(), and I am calling it in onPostCreate, after the map has been fully initialized. The call returns null though. This SO answer talks about a bug with getMyLocation(), but also mentions that it was fixed.


回答1:


To add to that LatLng of my location blue dot, use GoogleMap.getMyLocation() or if you want to update camera every time that location changes, GoogleMap.setOnMyLocationChangeListener(...) and then convert Location to LatLng.



来源:https://stackoverflow.com/questions/20109212/zoom-to-the-closest-level-that-still-shows-all-markers-including-the-blue-myloc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!