【问题标题】:ItemizedOverlay OSMDroidItemizedOverlay OSMDroid
【发布时间】:2012-08-19 09:56:28
【问题描述】:

我是 Android 开发和 Java 的新手,所以请原谅我的无知。

我在使用 ItemizedOverlay 向 Mapnik 地图添加精确点时遇到问题。我正在关注谷歌地图教程并尝试将其转换为 OSMDroid,但我无法让它工作。 在课堂打击中,错误以红色突出显示。如果有更多经验的人能指出我哪里出错了,我将不胜感激。

ItemizedOverlay 类:

public class CustomPoint extends ItemizedOverlay<OverlayItem>{

    private ArrayList<OverlayItem> mItemList = new ArrayList<OverlayItem>();
    private Context c;

public CustomPoint(Drawable pDefaultMarker, ResourceProxy pResourceProxy) {
        super(pDefaultMarker, pResourceProxy);
        // TODO Auto-generated constructor stub
    }


    public CustomPoint(Drawable m, Context context){
        this(m);
       c = context;     
        }


   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;
    }

    public boolean onSnapToItem(int arg0, int arg1, Point arg2, IMapView arg3)
    {
        // TODO Auto-generated method stub
        return false;
    }

    public void insertPinpoint(OverlayItem o) {
        // TODO Auto-generated method stub
        mItemList.add(o); 
        populate();

    }

}

调用 CustomPoint 类的 MainActivity 类:

public void onClick(DialogInterface dialog, int which) {
    OverlayItem overlayItem = new OverlayItem("Here I am", "2nd String",(GeoPoint)touchedPoint);
    CustomPoint custom = new CustomPoint(d, MainActivity.this);
    custom.insertPinpoint(overlayItem);
    overlayList.add(custom);
            }

【问题讨论】:

  • overlayList 是否添加到您的 MapView 中?
  • 谢谢帕特里克,我被困在这里了。我有这个代码 List overlayList = mapView.getOverlays();叠加列表.add(t);
  • 谢谢帕特里克,我被困在这里了。这不是由overlayList.add(custom) 完成的吗? ?我所遵循的教程之间的区别在于添加了资源代理......如果可能的话,我非常感谢这里的一些指导。

标签: android itemizedoverlay osmdroid


【解决方案1】:

你为什么不把你的类扩展到ItemizedIconOverlay

public class CustomPoint extends ItemizedIconOverlay<OverlayItem>{

    private ArrayList<OverlayItem> mItemList = new ArrayList<OverlayItem>();
    private Context c;

public CustomPoint(Master master,ArrayList<OverlayItem> pList,Drawable marker, ItemizedIconOverlay.OnItemGestureListener<OverlayItem> pOnItemGestureListener, ResourceProxy pResourceProxy) {
        super(pList, marker, pOnItemGestureListener, pResourceProxy);
        // TODO Auto-generated constructor stub
    }
}

【讨论】:

    猜你喜欢
    • 2012-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多