2

I want to add markers to my OSMdroid map. I am using OSMdroid version 5.5. The official tutorial suggests the following code:

//your items
ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
items.add(new OverlayItem("Title", "Description", new GeoPoint(0.0d,0.0d))); // Lat/Lon decimal degrees

//the overlay
ItemizedOverlayWithFocus<OverlayItem> mOverlay = new ItemizedOverlayWithFocus<OverlayItem>(items,
    new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
    @Override
    public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
    //do something
        return true;
    }
    @Override
    public boolean onItemLongPress(final int index, final OverlayItem item) {
        return false;
    }
}, mResourceProxy);  // <----- where to get this object from?
mOverlay.setFocusItemsOnTap(true);

mMapView.getOverlays().add(mOverlay);

However, I don't know where to get the mResourceProxy object from. All websites I found about this topic (including OSMdroid's GitHub page) are making use of the DefaultResourceProxyImpl class, which is deprecated since version 5.2.

Does anyone know how to add marker versions >= 5.2?

arne.z
  • 3,242
  • 3
  • 24
  • 46

1 Answers1

4

Okay, so I found out how to use it. The ItemizedOverlayWithFocus doesn't require a ResourceProxy at all. So you can use one of the following constructors:

public ItemizedOverlayWithFocus(Context pContext, List<Item> aList, OnItemGestureListener<Item> aOnItemTapListener) { ... }

public ItemizedOverlayWithFocus(List<Item> aList, OnItemGestureListener<Item> aOnItemTapListener, Context pContext) { ... }

public ItemizedOverlayWithFocus(List<Item> aList, Drawable pMarker, Drawable pMarkerFocused, int pFocusedBackgroundColor, OnItemGestureListener<Item> aOnItemTapListener, Context pContext) { ... }

This is how I adjusted the code from my question to make it work:

//your items
ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();
items.add(new OverlayItem("Title", "Description", new GeoPoint(0.0d,0.0d))); // Lat/Lon decimal degrees

//the overlay
ItemizedOverlayWithFocus<OverlayItem> mOverlay = new ItemizedOverlayWithFocus<OverlayItem>(
    this, items,  //  <--------- added Context this as first parameter
    new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() {
    @Override
    public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
    //do something
        return true;
    }
    @Override
    public boolean onItemLongPress(final int index, final OverlayItem item) {
        return false;
    }
});  // <----- removed the mResourceProxy parameter
mOverlay.setFocusItemsOnTap(true);

mMapView.getOverlays().add(mOverlay);
arne.z
  • 3,242
  • 3
  • 24
  • 46
  • 1
    Thanks for bringing this up, I'll update the tutorial – spy Dec 12 '16 at 00:39
  • Second constructor worked for me. Thanks. Please update the tutorial. I searched for several hours to get this one – Sarweshkumar C R Dec 12 '16 at 16:10
  • Now the official tutorial has neither context nor proxy - only two parameters. But the ItemizedOverlayWithFocus constructor still needs 3... – Dmytro Aug 27 '17 at 20:05