Search code examples
androidiconsmapsosmdroid

how to use custom pointers in osmdroid?


I am using OSMDroid and this code gives default markers to point my location. How do i put custom markers in place of the default markers? How do i import a new drawable?

anotherOverlayItemArray = new ArrayList<OverlayItem>();
anotherOverlayItemArray.add(new OverlayItem("KTM2", "KTM2", myLocation));
 ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay = new
          ItemizedIconOverlay<OverlayItem>( this, anotherOverlayItemArray,myOnItemGestureListener);

      mapView.getOverlays().clear();   
      mapView.getOverlays().add(anotherItemizedIconOverlay);  
      mapView.invalidate();

Solution

  • You can set a specific marker to each OverlayItem:

    OverlayItem item = new OverlayItem("KTM2", "KTM2", myLocation);
    Drawable myMarker = getResources().getDrawable(markerResId);
    item.setMarker(myMarker);
    anotherOverlayItemArray.add(item);
    

    You can also get rid of the ItemizedIconOverlay/OverlayItem approach by using the OSMBonusPack Marker.