首页 > 解决方案 > (谷歌地图)检查 LatLng 是否在可见区域经度的 80% 以内

问题描述

LinearLayout我有一个 android 布局,它有一个谷歌地图布局,底部覆盖了一个小地图。当用户选择地图上的标记时,这个小布局变得可见。现在,我想知道所选标记是否在选择时被小布局覆盖,比如它是否在地图经度可见区域的前 80% 范围内。我玩过,maps.getProjection().getVisibleRegion()但我不确定我从这里去哪里。提前致谢在此处输入图像描述

标签: androidgoogle-mapsandroid-layoutgoogle-maps-markers

解决方案


确认地图已加载后,请尝试以下操作:

LatLngBounds.Builder builder = new LatLngBounds.Builder();

LatLngBounds bounds = builder.build();
LatLng ne = bounds.northeast;
LatLng sw = bounds.southwest;

Point neBoundInPx = mGoogleMap.getProjection().toScreenLocation(ne);
Point swBoundInPx = mGoogleMap.getProjection().toScreenLocation(sw);

Point newBottomBoundInPx = new Point (neBoundInPx.x , swBoundInPx.y - bottomLinearLayout.getHeight());

LatLng newBottomBoundInPxLatLng = mGoogleMap.getProjection().fromScreenLocation(newBottomBoundInPx);

if(placeLatLng.latitude <= ne.latitude &&
        placeLatLng.longitude >= sw.longitude &&
        placeLatLng.latitude >= newBottomBoundInPxLatLng.latitude &&
        placeLatLng.longitude <= ne.longitude) {
            //Yor place is above the linearLayout at the Bottom.
}

推荐阅读