0

How do i get the index position of the ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay when the user taps the icon? For example, when a user taps/clicks the first icon it should get the integer 0

List<GeoPoint> nodes = nodeCoordinates();
ArrayList<OverlayItem> anotherOverlayItemArray = new ArrayList<>();
Drawable newMarker = getResources().getDrawable(R.drawable.marker_node);

for(int i = 0; i < nodes.size(); i++) {
    anotherOverlayItemArray.add(new OverlayItem("Road", "Nodes", nodes.get(i)));
    anotherOverlayItemArray.get(i).setMarker(newMarker);
}

ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
            = new ItemizedIconOverlay<>(
            this, anotherOverlayItemArray, null);
map.getOverlays().add(anotherItemizedIconOverlay);
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Mariel
  • 169
  • 2
  • 5
  • 18

1 Answers1

1

There's an example here https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/data/SampleMilitaryIconsItemizedIcons.java

ack, formatting issues....

`

itemOverlay = new ItemizedOverlayWithFocus<>(new ArrayList(), new ItemizedIconOverlay.OnItemGestureListener() { @Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) { Toast.makeText( context, "Item '" + item.getTitle() + "' (index=" + index + ") got single tapped up", Toast.LENGTH_LONG).show(); return true; }

                        @Override
                        public boolean onItemLongPress(final int index, final OverlayItem item) {
                             Toast.makeText(
                                     context,
                                     "Item '" + item.getTitle() + "' (index=" + index
                                             + ") got long pressed", Toast.LENGTH_LONG).show();
                             return false;
                        }
                   }, context);

`

spy
  • 3,199
  • 1
  • 18
  • 26