android - LatLngBounds 或 CameraUpdate 不显示 Maps Lite 模式中的所有点

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

我有一张 map ,其中显示了由折线连接的一系列点,该 map 是 LiteMode,但在某些情况下,当使用这些点创建 LatLngBounds 并更新相机时,一些点会被遗漏在 map 之外。

  LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (LatLng latLng : listPoints) {
        builder.include(latLng);
    }
    LatLngBounds bounds = builder.build();
    int padding = 0; //offset from edges of the map in pixels
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
    map.moveCamera(cu);

我该如何解决?

通过折线,我们可以看到即使更改填充,它们也看不见:1 所以如果我删除 LiteMode 就会看到: 2]

最佳答案

我解决了这个问题!
根据谷歌地图精简模式 documentation说:

Camera position, zoom, and animation
Supported? Partly
You can set the camera target and zoom, but not the tilt or bearing. Zoom level is rounded to the nearest integer in lite mode. Calling GoogleMap.moveCamera() will give you another static map image. For more information on setting and manipulating the camera, see Changing the View.

我的解决方案是从 map 中获取可见区域并进行比较,看看我的列表中是否有任何点在该区域之外,如果是,我应用 ZoomOut 来充分缩小相机,以便我的所有点都在可见区域。

    for (LatLng latLng : listPoints) {
                if (!(map.getProjection().getVisibleRegion().latLngBounds.contains(latLng))) {
                    map.moveCamera(CameraUpdateFactory.zoomOut());
                    break;
                }
            }

据我了解,显然问题在于,如果缩放级别为 7.4,则通过四舍五入到最接近的整数来正确显示 map 上的所有点:7,与 LiteMode This disabled 舍入为 8 时相比,宝贵的 .4 利润损失了。

我不知道这是否是最佳选择,但问题已解决。欢迎任何意见! :)

关于android - LatLngBounds 或 CameraUpdate 不显示 Maps Lite 模式中的所有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41317561/

相关文章:

android - 谷歌地图标记可点击区域

javascript - 谷歌地图 API v3 : Initial View is Fine but Gray Box with No Map if View is changed

android - 如何将动态数据传递给 android 中的自定义信息窗口适配器?

android - 使用 CLI 在 Titanium Studio 中手动构建 APK

android - 我正在使用 Firebase,在创建 firebase 对象时出现此异常

google-maps - 授予权限后重新加载我的位置按钮

java - 返回单一路线的交互式 Android Google map

android - Google Maps v2 上的动画透明圆圈动画不正确

java - 这是启动 Activity 的正确方法吗?

android - Gradle buildType/productFlavor 使用意外的 buildConfigField