我正在用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行中,我出现了一条红线,并显示一条错误,提示修复项目设置。我很困惑。为什么我会在日食中收到此错误?请帮我
最佳答案
您可以使用类似的方法。
-扩展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);
}
关于android - 将ItemizedOverlay添加到我的 map View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10573586/