how to add more marker in osm map in android

后端 未结 1 1930
醉话见心
醉话见心 2021-01-22 04:24

I\'ve found a solution how to map balloon in openstreet map I customize osmbonuspack according to my need is work fine but is only show one map.

How do I add more then o

相关标签:
1条回答
  • 2021-01-22 04:58

    Use Itemized Overlay like this (populate method is most important)

    public class CustomOverLay extends ItemizedOverlay<OverlayItem> {
    
    private ArrayList<OverlayItem> overlayItems = new ArrayList<OverlayItem>();
    private MapView mapView;
    
    public CustomOverLay(Drawable drawable, MapView mapView) {
        super(boundCenterBottom(drawable));
        this.mapView = mapView;
    }
    
    public void addOverlayItem(OverlayItem item) {
        overlayItems.add(item);
        populate();
    }
    
    @Override
    protected OverlayItem createItem(int index) {
        return overlayItems.get(index);
    }
    
    @Override
    public int size() {
        return overlayItems.size();
    }
    
    @Override
    protected boolean onTap(int index) {
        return true;
    }
    

    }

    and once you did this follow the code bellow, add OverlayItem for the number markers you want to place in the Map

    List<Overlays> mapOverlays = mapView.getOverlays();
    CustomOverLay overlays = new CustomOverLay(drawable, mapView);
    
    GeoPoint p = new GeoPoint(getLat(util.getLatitude()), getLong(util.getLongitude()));
    OverlayItem overlayItem = new OverlayItem(p, "", "");
    overlays.addOverlayItem(overlayItem);
    
    
    GeoPoint p = new GeoPoint(getLat(util.getLatitude()), getLong(util.getLongitude()));
    OverlayItem overlayItem = new OverlayItem(p, "", "");
    overlays.addOverlayItem(overlayItem);
    
    ..... so on
    
    mapOverlays.add(overlays);
    

    cheers

    0 讨论(0)
提交回复
热议问题