OSMDroid: onTap example

前端 未结 1 512
后悔当初
后悔当初 2021-01-14 14:08

I\'ve started to study Android few weeks ago and now I need your help. My task is create off-line map (using OSMDroid and Mobile Atlas Creator), with two markers on it, path

相关标签:
1条回答
  • 2021-01-14 14:36

    You need to create new class, like this:

        public class MyOwnItemizedOverlay extends ItemizedIconOverlay<OverlayItem> {
        protected Context mContext;
    
        public MyOwnItemizedOverlay(final Context context, final List<OverlayItem> aList) {
             super(context, aList, new OnItemGestureListener<OverlayItem>() {
                    @Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                            return false;
                    }
                    @Override public boolean onItemLongPress(final int index, final OverlayItem item) {
                            return false;
                    }
                  } );
            // TODO Auto-generated constructor stub
             mContext = context;
        }
    
        @Override 
        protected boolean onSingleTapUpHelper(final int index, final OverlayItem item, final MapView mapView) {
            //Toast.makeText(mContext, "Item " + index + " has been tapped!", Toast.LENGTH_SHORT).show();
            AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
            dialog.setTitle(item.getTitle());
            dialog.setMessage(item.getSnippet());
            dialog.show();
            return true;
        }
    }
    

    Here is how to use it in the first (main) class:

    MapView mapView = new MapView(this, 256); //constructor
    //some code from te question
    
    ArrayList<OverlayItem> overlayItemArray = new ArrayList<OverlayItem>();                
    OverlayItem olItem = new OverlayItem("Here", "SampleDescription", new GeoPoint(54.332, 48.389));//marker
    
    MyOwnItemizedOverlay overlay = new MyOwnItemizedOverlay(this, overlayItemArray);
    mapView.getOverlays().add(overlay);        
    setContentView(mapView); //displaying the MapView
    

    That's all. Good luck! links: http://code.google.com/p/osmdroid/issues/detail?id=245#makechanges

    0 讨论(0)
提交回复
热议问题