我正在使用android maps v2,我正在使用填充来移动地图控件和google的徽标:
mMap.setPadding(0, 0, 0, padding_in_px);
另一方面,我需要知道地图可见部分的限制是什么:
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
问题在于,如果我填充填充,该函数不会返回地图上可见区域的边界,而只返回可见区域的边界减去填充区域。
当地图有填充mMap.getProjection()时,有没有办法.getVisibleRegion()返回实际的可见边界而不是地图边界 - 填充边界?
由于
答案 0 :(得分:6)
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
可以为您提供nearLeft
和nearRight
属性,它们是LatLng
类型。
您可以使用toScreenLocation()将nearLeft
或nearRight
转换为屏幕点。一旦获得可见区域的底部点,就可以使用该点加上放置的填充像素(例如: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);