【问题标题】:Android maps padding and map boundsAndroid 地图填充和地图边界
【发布时间】:2015-07-13 17:14:29
【问题描述】:

我正在使用 android maps v2,我正在使用填充来移动地图控件和 google 的徽标:

       mMap.setPadding(0, 0, 0, padding_in_px);

另一方面,我需要知道地图可见部分的限制是什么:

       LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;

问题是,如果我放置一个填充,该函数不会返回地图上可见区域的边界,而只会返回可见区域的边界减去填充区域。

当地图有填充时,是否有任何方法 mMap.getProjection().getVisibleRegion() 返回实际可见边界而不是地图边界 - 填充边界?

谢谢

【问题讨论】:

    标签: android google-maps


    【解决方案1】:

    LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds; 可以给你nearLeftnearRight 属性,它们是LatLng 类型。

    您可以使用toScreenLocation()nearLeftnearRight 转换为屏幕点。获得可见区域的底点后,您可以使用该点加上您放置的填充像素(例如:100,padding_in_px)。然后您可以使用fromScreenLocation() 将点转换回。

    LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
    LatLng nearLeft = bounds.nearLeft
    Point visibleNearLeftPoint =  mMap.getProjection().toScreenLocation(nearLeft);
    Point screenBottomLeftPoint = new Point(visibleNearLeftPoint.x, visibleNearLeftPoint.y + padding_in_px);
    LatLng screenBottomLatLng = mMap.getProjection().fromScreenLocation(screenBottomLeftPoint);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多