我正在使用osm开发一个地图应用程序。我想在我的mapview上创建一些标记。即时通讯使用以下代码:
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中得到这个错误?请帮帮我
答案 0 :(得分: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);
}
答案 1 :(得分:-1)
尝试右键单击您的项目 - &gt; android工具 - &gt;修复项目(或类似的东西)。也尝试清理你的项目。