显示叠加在Android中落入当前可见区域Google Map的项目

时间:2012-10-17 09:51:19

标签: android google-maps

我有很多数据要显示在谷歌地图上,但我想要的只是将那些属于谷歌地图当前可见空间的元素。 这该怎么做?提供一些有用的教程链接。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:3)

请检查此链接:https://github.com/ketankpatel/android/tree/master/PinDropAnimation

它会在可见区域掉落针脚。

代码段在这里:

private void putEventOverlay() {

        if (mapData.getZoomLevel() < 3) {
            mapData.getController().setZoom(3);

        }
        final MyLocationOverlay myLocationOverlay = new MyLocationOverlay(HomeActivity.this, mapData);
        mapData.getOverlays().add(myLocationOverlay);
        myLocationOverlay.enableMyLocation();

        GeoPoint center = mapData.getMapCenter();
        Integer latspan = mapData.getLatitudeSpan();
        Integer lonspan = mapData.getLongitudeSpan();
        Integer maxLat = center.getLatitudeE6() + (latspan / 2);
        Integer maxLon = center.getLongitudeE6() + (lonspan / 2);
        Integer minLat = center.getLatitudeE6() - (latspan / 2);
        Integer minLon = center.getLongitudeE6() - (lonspan / 2);

        double maxLatitude, minLatitude, maxLongitude, minLongitude;

        maxLatitude = maxLat / 1E6;
        minLatitude = minLat / 1E6;
        maxLongitude = maxLon / 1E6;
        minLongitude = minLon / 1E6;

        Drawable marker = getResources().getDrawable(R.drawable.marker);
        EventDetailModel tempDetailModel = null;
        ArrayList<EventDetailModel> tempDetailList = dbHelper.getMapSortedEventData(minLatitude, maxLatitude, minLongitude,maxLongitude);

        if (tempDetailList.size() != 0) {
            mapData.getOverlays().clear();
        }
        for (int i = 0; i < tempDetailList.size(); i++) {
            tempDetailModel = (EventDetailModel) tempDetailList.get(i);
            MapItemizedOverlay itemizedOverlay = new MapItemizedOverlay(marker);
            itemizedOverlay.addOverlay(HomeActivity.this, tempDetailModel);
            mapData.getOverlays().add(itemizedOverlay);
        }

        mapData.invalidate();

    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {

        if (ev.getAction() == MotionEvent.ACTION_UP) {

            putEventOverlay();
        }
        return super.dispatchTouchEvent(ev);
    }
  • Vandit

答案 1 :(得分:0)

我假设有很多数据&#39;你的意思是一些标记来绘制。获取当前地图边界。当您在数据上循环,添加标记时,请使用bounds.contains()来查看标记的位置是否可见。如果是这样,请将其添加到地图中。