My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 245: ItemizedOverlay<OverlayItem>:onTap on called when tapping
14 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Apr 2013

Sign in to add a comment
Reported by, Jul 27, 2011
I'm using osmdroid-android-3.0.5.jar‬ to embed OSMap in my app.
What steps will reproduce the problem?
1. Open the app.
2. Tap an item.
3. onTap(index i) not called

What is the expected output? What do you see instead?
breakpoint inside onTap nor reached.

What version of the product are you using? On what operating system?
2.2 emulator and also device - samsung galaxy

Please provide any additional information below.
same problem with osmdroid-android-3.0.4.jar


       MapView mapView = new MapView(this, 256);
        mapView.getController().setCenter(new GeoPoint(39.461078, 2.856445));
        List<Overlay> mapOverlays = mapView.getOverlays();
		Drawable drawable = this.getResources().getDrawable(R.drawable.icon);

		MapItemizedOverlay itemizedoverlay = new MapItemizedOverlay(drawable,this);

		double lat = 39.461078;
		double lng = 2.856445;
		GeoPoint homePoint = new GeoPoint(lat,lng);
		OverlayItem overlayitem = new OverlayItem("Home Sweet Home", "name", homePoint);


public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem>
	 private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	 private Context mContext;
	 public MapItemizedOverlay(Drawable defaultMarker, Context context)
		 super(defaultMarker, new DefaultResourceProxyImpl(context));
		 mContext = context;
	 public void addOverlay(OverlayItem overlay)
	 protected OverlayItem createItem(int i)
		 return mOverlays.get(i);
	 public int size()
		 return mOverlays.size();
	 protected boolean onTap(int index)
		 OverlayItem item = mOverlays.get(index);
		 AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		 return true;
	 //boolean onTap(GeoPoint p, MapView mapView)
	//	 return false;

	public boolean onSnapToItem(int arg0, int arg1, Point arg2, MapView arg3) {
		// TODO Auto-generated method stub
		return false;


Aug 9, 2011
Doesn't work for me either.
Is there a workaround or another way on how to execute methods for each marker?
Aug 18, 2011
Same here. Just ported an app from Google Maps to osmdroid, and the onTap doesn't work. I use it a lot on driving directions, to tap on the turn markers to get some text info in a popup window.

In my original code, I'm using the @Override annotation in the onTap method. In osmdroid, I can't. That method doesn't exist.

Aug 27, 2011
doesntr work for me teither
Sep 11, 2011
Hi. I've the same issue. anybody knows how to solve it?
Oct 25, 2011
I have the same problem with that. I think they change one method by the other one (onSnapToItem by onTap).
Oct 27, 2011
Why it says:

	public boolean onSnapToItem(int pX, int pY, Point pSnapPoint, MapView pMapView) {
		// TODO Implement this!
		return false;

Feb 20, 2012
'up' !

I'm porting an application that uses an old snapshot of osmdroid, and it tries to override onTap() in an ItemizedOverlay<> class. But since r417 ( ), this method has been removed.

It is still documented in 4.0 docs of Android API:

Is this a bug ? Maybe there is a known workaround on how to get the same behavior, but I could not find it after searching different forums/groups/source code.

Any help very appreciated :)

May 2, 2012
Has anyone solved this?
May 2, 2012

I also got this problem some weeks ago... Finally, I solved it using ItemizedOverlayWithFocus class and its onItemSingleTapUp method.
May 9, 2012
sergi, can you post an example of using ItemizedOverlayWithFocus within a class? Thanks!
May 16, 2012
I encountered exactly the same issue. And this is probably the only real issue when porting an app from GoogleAPI to osmdroid. So solutions should be documented well. Here is my modest contribution. 

First of all, look at ItemizedIconOverlay, as it does most of what we want. 
After struggling a lot trying to sub-class ItemizedIconOverlay with my custom onSingleTapUpHelper, I finally made a class containing ItemizedIconOverlay. 
Applied to your implementation, it looks like this:

public class MyOwnItemizedOverlay {
	protected ItemizedIconOverlay<OverlayItem> mOverlay;
	protected Context mContext;
	protected Drawable mMarker;

	public MyOwnItemizedOverlay(Drawable marker, Context context) {
		mContext = context;
		ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
		ResourceProxy resourceProxy = (ResourceProxy) new DefaultResourceProxyImpl(mContext);
		mMarker = marker;

		mOverlay = new ItemizedIconOverlay<OverlayItem>(
				items, mMarker, 
				new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
			@Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
				return onSingleTapUpHelper(index, item);
			@Override public boolean onItemLongPress(final int index, final OverlayItem item) {
				return true;
		}, resourceProxy);

	public boolean onSingleTapUpHelper(int i, OverlayItem item) {
		//Toast.makeText(mContext, "Item " + i + " has been tapped!", Toast.LENGTH_SHORT).show();
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		return true;
	public void addItem(OverlayItem item){
	public ItemizedIconOverlay<OverlayItem> getOverlay(){
		return mOverlay;

Using this class is nearly identical to using a sub-class of ItemizedOverlay (as you did in your MapActivity), except that adding the overlay to the map is done this way: 

Note that you can also easily implement onItemLongPress, if desired. 

May 17, 2012
Thanks man, that worked out just awesomely! :)
May 17, 2012
Project Member #14 neilboyd
See also  issue 343 
Jun 23, 2012
Find below a very simple and "regular" implementation, as MyOwnItemizedOverlay is now a "true" overlay. 

class MyOwnItemizedOverlay extends ItemizedIconOverlay<OverlayItem> {
	protected Context mContext;
	public MyItemizedOverlay(final Context context, final List<OverlayItem> aList) {
		 super(context, aList, new OnItemGestureListener<OverlayItem>() {
            @Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                    return false;
            @Override public boolean onItemLongPress(final int index, final OverlayItem item) {
                    return false;
    	  } );
	  mContext = context;
	@Override protected boolean onSingleTapUpHelper(final int index, final OverlayItem item, final MapView mapView) {
		//Toast.makeText(mContext, "Item " + index + " has been tapped!", Toast.LENGTH_SHORT).show();
		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
		return true;

And to use it in your activity:
ArrayList<OverlayItem> list = new ArrayList<OverlayItem>();
MyOwnItemizedOverlay<OverlayItem> overlay = new MyOwnItemizedOverlay(this, list);

Aug 21, 2012
Thanks for sharing matheu.  The constructor name is wrong in comment 16 above, it should be public MyOwnItemizedOverlay(...)
Jan 25, 2013
Project Member #20
This issue should be closed. We have a samples app that covers handling item clicks.

If there is any issue here it is that we aren't implementing an onTap() method as the Google Maps API does (how did that happen?).
Jan 25, 2013
Project Member #21
 Issue 343  has been merged into this issue.
Apr 11, 2013
Project Member #22
 Issue 225  has been merged into this issue.
Apr 11, 2013
Project Member #23
In r1209 we have added onTap and OnFocusChangedListenerSupport.

Status: Fixed
Apr 12, 2013
Hi kurtzmarc,

If we want to catch a tap event at an overlay, what's the difference between new way with ItemizedOverlay's onTap and old way with ItemizedIconOverlay's onSingleTapUpHelper ?
Personally I extend ItemizedIconOverlay and use helper methods for both single tap and long press.
Now we can catch the tap event with 2 ways?

Apr 12, 2013
Project Member #25
ItemizedIconOverlay is a concrete implementation of the ItemizedOverlay - it really belongs in the samples app because it's more of an example of how you can implement ItemizedOverlay. It could probably be rewritten to take advantage of onTap().

It's up to you which one you use. It looks like the ItemizedIconOverlay does not take the "hotspot" into account, so you may have better results with onTap().
Sign in to add a comment

Powered by Google Project Hosting