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 ItemizedOverla
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
{
private ArrayList mItemList = new ArrayList();
public OsmMapsItemizedOverlay(ArrayList pList,
ItemizedIconOverlay.OnItemGestureListener 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()
{
@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);
}