0

我已经定义了地图叠加层,并且可以毫无问题地显示标记。当我点击一个时,我现在正试图让一些事情发生,但这个事件似乎永远不会触发。我确定我错过了一些明显的东西......

public class MapBlobCollection extends ItemizedOverlay<OverlayItem> {

        @SuppressWarnings("serial")
        public class ItemTappedEvent extends EventObject
        {
            public ItemTappedEvent(int itemIndex) {
                super(itemIndex);
            }
        }

        private ArrayList<OverlayItem> myOverlays ;

        public MapBlobCollection(Drawable defaultMarker) {
            super(boundCenterBottom(defaultMarker));
            myOverlays = new ArrayList<OverlayItem>();
            populate();
        }

        public void addOverlay(OverlayItem overlay){
            myOverlays.add(overlay);
            populate();
        }

        @Override
        protected OverlayItem createItem(int i) {
            return myOverlays.get(i);
        }

        // Removes overlay item i
        public void removeItem(int i){
            myOverlays.remove(i);
            populate();
        }

        // Returns present number of items in list
        @Override
        public int size() {
            return myOverlays.size();
        }


        public void addOverlayItem(OverlayItem overlayItem) {
            myOverlays.add(overlayItem);
            populate();
        }


        public void addOverlayItem(int lat, int lon, String title) {
            try {
                GeoPoint point = new GeoPoint(lat, lon);
                OverlayItem overlayItem = new OverlayItem(point, title, null);
                addOverlayItem(overlayItem);    
            } catch (Exception e) {
                // TODO: handle exception
                e.printStackTrace();
            }
        }

        @Override
        protected boolean onTap(int index) {
            super.onTap(index);
            Log.d("TESTING","Triggering tap event on " + Integer.toString(index));
            EventManager.triggerEvent(this, new ItemTappedEvent(index));
            return true;
        }
}

基本上,调试日志条目不会被写入,事件也不会触发。

此外,我的地图视图本身并没有平移(应该是它,没有我的任何额外代码吗?),尽管设置了 setBuitInZoomControls(true),但这些也没有出现......所以也许地图视图本身有问题?

mapview 在布局中定义为:

<com.google.android.maps.MapView
android:id="@+id/indexMapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:apiKey="@string/mapskey_release"/>

而且我没有覆盖任何平局事件或任何东西......

4

2 回答 2

1

我相信你需要添加

android:clickable="true"

到您的地图视图

于 2012-09-19T09:06:07.377 回答
0

尝试将超级功能移到最后:

   @Override
     protected boolean onTap(int index) {
         Log.d("TESTING","Triggering tap event on " + Integer.toString(index));
         EventManager.triggerEvent(this, new ItemTappedEvent(index));
         return super.onTap(index);
     } 
于 2012-09-19T09:19:23.630 回答