【问题标题】:Zoom to the closest level that still shows all markers, including the blue MyLocation marker缩放到仍然显示所有标记的最接近的级别,包括蓝色的 MyLocation 标记
【发布时间】:2013-11-21 23:31:24
【问题描述】:

我想缩放和定位我的GoogleMap,以便所有标记(包括蓝色的MyLocation 标记)都可见。 This SO question 展示了如何为所有手动添加的标记执行此操作,但我不确定如何获取MyLocation 标记的句柄,该标记在调用setMyLocationEnabled(true) 后自动添加,以便将其传递给@987654327 @。

我尝试过使用GoogleMap.getMyLocation(),在地图完全初始化后,我在onPostCreate 中调用它。该调用返回nullThis SO answer 谈到了 getMyLocation() 的一个错误,但也提到它已修复。

【问题讨论】:

    标签: android google-maps-markers google-maps-android-api-2


    【解决方案1】:

    要添加到我所在位置蓝点的LatLng,请使用GoogleMap.getMyLocation(),或者如果您想在每次位置更改时更新相机,请使用GoogleMap.setOnMyLocationChangeListener(...),然后将Location 转换为LatLng

    【讨论】:

    • 我在onPostCreate 中打电话给getMyLocation(),但我只收到nullThis SO answer 谈到了该功能的一个错误,但也表示它应该已修复。
    • @mattblang onPostCreate 打电话给getMyLocation 为时尚早。单击某个按钮时使用监听器或调用它。
    • 我也在onResume 中尝试过它是否可以工作,但仍然是nullonLocationChanged 的问题是监听器不会在初始化时触发。我注意到getMyLocation 已被弃用,因此我切换到他们在getMyLocation 文档中引用的演示文件中使用的方法。使用我链接的 SO 问题,我能够让它工作。剩下的一个问题是填充没有做任何事情,所以标记在最边缘。
    猜你喜欢
    • 2019-05-25
    • 2016-02-17
    • 2014-11-28
    • 2012-07-18
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 2022-06-16
    • 1970-01-01
    相关资源
    最近更新 更多