Adding ItemizedOverlay to my mapview

前端 未结 2 730
情歌与酒
情歌与酒 2021-01-23 00:11

i am develpoing a map application with osm. i want to create some marker on my mapview. im using the folowwing code:

this.mMyLocationOverlay = new ItemizedOverla         


        
相关标签:
2条回答
  • 2021-01-23 00:28

    You can use something like that. - extend ItemizedOverlay

    package dispatch.driver.osmMaps;
    
    import java.util.ArrayList;
    
    import org.osmdroid.ResourceProxy;
    import org.osmdroid.api.IMapView;
    import org.osmdroid.views.overlay.ItemizedIconOverlay;
    import org.osmdroid.views.overlay.OverlayItem;
    
    import android.graphics.Point;
    
    public class OsmMapsItemizedOverlay extends ItemizedIconOverlay<OverlayItem>
    {
        private ArrayList<OverlayItem> mItemList = new ArrayList<OverlayItem>();
    
        public OsmMapsItemizedOverlay(ArrayList<OverlayItem> pList,
                ItemizedIconOverlay.OnItemGestureListener<OverlayItem> pOnItemGestureListener, ResourceProxy pResourceProxy)
        {
            super(pList, pOnItemGestureListener, pResourceProxy);
            mItemList = pList;
            // TODO Auto-generated constructor stub
        }
    
        public void addOverlay(OverlayItem aOverlayItem)
        {
            mItemList.add(aOverlayItem);
            populate();
        }
    
        public void removeOverlay(OverlayItem aOverlayItem)
        {
            mItemList.remove(aOverlayItem);
            populate();
        }
    
        @Override
        protected OverlayItem createItem(int i)
        {
            return mItemList.get(i);
        }
    
        @Override
        public int size()
        {
            if (mItemList != null)
                return mItemList.size();
            else
                return 0;
        }
    
        @Override
        public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3)
        {
            // TODO Auto-generated method stub
            return false;
        }
    
    }
    

    And in your activity class call

    private void PrepareItemizedOverlay()
        {
            /* itemized overlay */
            mItemizedOverlay = new OsmMapsItemizedOverlay(mItems,
                    new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>()
                    {
                        @Override
                        public boolean onItemSingleTapUp(final int index, final OverlayItem item)
                        {
    
                            Toast.makeText(OsmMapsActivity.this,
                                    "Item '" + item.mTitle + "' (index=" + index + ") got single tapped up",
                                    Toast.LENGTH_LONG).show();
    
                            return true; // We 'handled' this event.
                        }
    
                        @Override
                        public boolean onItemLongPress(final int index, final OverlayItem item)
                        {
    
                            Toast.makeText(OsmMapsActivity.this,
                                    "Item '" + item.mTitle + "' (index=" + index + ") got long pressed", Toast.LENGTH_LONG)
                                    .show();
    
                            return true;
                        }
                    }, mResourceProxy);
        }
    

    to add a new overlay you can use something like this:

    {    OverlayItem overlayItem;
    
    
                overlayItem = new OverlayItem("Center", "Center", (GeoPoint) aPoint);
    
    
    
                mItemizedOverlay.addOverlay(overlayItem);
    
                mMapView.getOverlays().clear();
                mMapView.getOverlays().add(mItemizedOverlay);
                mMapView.getController().animateTo(aPoint);
    }
    
    0 讨论(0)
  • 2021-01-23 00:46

    Try to do a right click on your project -> android tools -> Fix project (or something like this). Also try to clean your project.

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