首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Google v2 newLatLngBounds在多窗口模式下使用百分比填充抛出错误

Google v2 newLatLngBounds在多窗口模式下使用百分比填充抛出错误
EN

Stack Overflow用户
提问于 2016-10-24 18:12:17
回答 1查看 2K关注 0票数 4

我正在用基于设备LatLngBounds百分比的填充集将相机动画到width上,这样它就可以在小型设备上工作。

这甚至可以在带有4英寸显示器的小型设备上工作,但是它在Android7.0中的多窗口模式和之前支持多窗口模式的设备上失败,例如。银河S7.

在多窗口模式下的设备上,我得到以下异常:

代码语言:javascript
运行
复制
Fatal Exception: java.lang.IllegalStateException: Error using newLatLngBounds(LatLngBounds, int, int, int): View size is too small after padding is applied.

这是可疑代码:

代码语言:javascript
运行
复制
private void animateCamera() {

    // ...

    // Create bounds from positions
    LatLngBounds bounds = latLngBounds(positions);

    // Setup camera movement
    final int width = getResources().getDisplayMetrics().widthPixels;
    final int height = getResources().getDisplayMetrics().heightPixels;
    final int padding = (int) (width * 0.40); // offset from edges of the map in pixels
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);

    mMap.animateCamera(cu);
}

如何正确地将newLatLngBounds中的填充设置为在所有设备宽度和多窗口模式下工作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-24 19:22:18

解决方案是在宽度和高度之间选择最小的度量,因为在多窗口模式下,高度可以小于宽度:

代码语言:javascript
运行
复制
private void animateCamera() {

    // ...

    // Create bounds from positions
    LatLngBounds bounds = latLngBounds(positions);

    // Setup camera movement
    final int width = getResources().getDisplayMetrics().widthPixels;
    final int height = getResources().getDisplayMetrics().heightPixels;
    final int minMetric = Math.min(width, height);
    final int padding = (int) (minMetric * 0.40); // offset from edges of the map in pixels
    CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, width, height, padding);

    mMap.animateCamera(cu);
}
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40224820

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档