我想在我的OSMdroid地图中添加标记。我使用的是OSMdroid 5.5版。 official tutorial建议使用以下代码:
//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);
但是,我不知道从哪里获取mResourceProxy
对象。我发现的有关此主题的所有网站(包括OSMdroid的GitHub页面)都使用了DefaultResourceProxyImpl
类,该版本自5.2版以来已弃用。
有谁知道如何添加标记版本&gt; = 5.2?
答案 0 :(得分:4)
好的,所以我发现了如何使用它。 ItemizedOverlayWithFocus
根本不需要ResourceProxy。因此,您可以使用以下构造函数之一:
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) { ... }
这是我从我的问题中调整代码以使其工作的方式:
//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);