2

我正在使用 osm 开发地图应用程序。我想在我的地图视图上创建一些标记。我使用以下代码:

this.mMyLocationOverlay = new ItemizedOverlay<OverlayItem>(this, items,
                new ItemizedOverlay.OnItemGestureListener<OverlayItem>() {
                    @Override
                    public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                        Toast.makeText(
                                SampleWithMinimapItemizedoverlay.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(
                                SampleWithMinimapItemizedoverlay.this,
                                "Item '" + item.mTitle + "' (index=" + index
                                        + ") got long pressed", Toast.LENGTH_LONG).show();
                        return false;
                    }
                }, mResourceProxy);

...

但在“new ItemizedOverlay.OnItemGestureListener”下的第 2 行中,我得到一条红线和一个错误,指出修复项目设置。我很困惑。为什么我在eclipse中得到这个错误?请帮我

4

2 回答 2

3

你可以使用类似的东西。- 扩展 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;
    }

}

在你的活动课上

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

要添加新的叠加层,您可以使用以下内容:

{    OverlayItem overlayItem;


            overlayItem = new OverlayItem("Center", "Center", (GeoPoint) aPoint);



            mItemizedOverlay.addOverlay(overlayItem);

            mMapView.getOverlays().clear();
            mMapView.getOverlays().add(mItemizedOverlay);
            mMapView.getController().animateTo(aPoint);
}
于 2012-05-14T14:32:35.493 回答
-1

尝试右键单击您的项目-> android 工具-> 修复项目(或类似的东西)。还要尝试清理您的项目。

于 2012-05-13T17:08:01.030 回答