调整地图以包含标记信息窗口

时间:2015-09-04 07:24:35

标签: android osmdroid

我正在使用osmdroid和osmbonuspack库。在活动中,我有一个带有来自osmbonuspack的几个标记的地图,每个标记在点击时打开一个InfoWindow。但是当标记靠近MapView的顶部边缘时,它的信息窗口会超出边界。有没有办法调整mapview,以便标记的InfoWindow完全呈现类似于这个iOS库? https://www.mapbox.com/ios-sdk/examples/marker/

1 个答案:

答案 0 :(得分:0)

我设法通过覆盖标准的MarkerInfoWindow onOpen方法来解决这个问题:

@Override
public void onOpen(Object item) {
    super.onOpen(item);
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            int[] infoWindowTop = {0, 0};
            int[] mapViewTop = {0, 0};
            mView.getLocationOnScreen(infoWindowTop);
            mMapView.getLocationOnScreen(mapViewTop);
            int rightEnd = infoWindowTop[0] + mView.getWidth();
            int dy = infoWindowTop[1] - mapViewTop[1];
            int dx = infoWindowTop[0];
            int dx_right = mMapView.getWidth() - rightEnd;
            if (dy < 0 && dx < 0) {
                smoothScrollBy(mMapView, dx, dy);
                return;
            }
            if (dy < 0 && dx_right < 0) {
                smoothScrollBy(mMapView, -dx_right, dy);
                return;
            }
            if (dx < 0) {
                smoothScrollBy(mMapView, dx, 0);
                return;
            }
            if (dy < 0) {
                smoothScrollBy(mMapView, 0, dy);
                return;
            }
            if (dx_right < 0) {
                smoothScrollBy(mMapView, -dx_right, 0);
                return;
            }
        }
    }, 500);

}
相关问题