问题
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 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);
...
but in line 2 under the "new ItemizedOverlay.OnItemGestureListener" i get a red line and an error that says fix project setup. i am very confiused. why i get this error in eclipse? please help me
回答1:
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);
}
回答2:
Try to do a right click on your project -> android tools -> Fix project (or something like this). Also try to clean your project.
来源:https://stackoverflow.com/questions/10573586/adding-itemizedoverlay-to-my-mapview