Add marker to OSMdroid 5.5 map

强颜欢笑 提交于 2019-12-01 11:15:13

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!