Clickable List within OverlayItem (MapView for Android)

672 Views Asked by At

I have a map view with several pins plotted on different addresses. All works very well. The issue arises when you have more than one item pointing to the same address. For example,

Unit 1/ 45 ABC Street, XYZ
Unit 7/ 45 ABC Street, XYZ.

I use the following line of code to fetch the lat and long in order to create a GeoPoint.

List<Address> listfromGoogle = gc.getFromLocationName(a, 1);

where a is the address and gc is the GeoCoder object.

According the API , the two addresses mentioned above returns the same coordinates.

So while plotting the pins on the map, they overwrite each other ending up with one pin for multiple addresses.

I tried to implement a list that displays all the repeating addresses on the balloon. The attempt was in vain and I realised that

OverlayItem(GeoPoint point, java.lang.String title, java.lang.String snippet) 

allows me only to supply two strings to be shown on the balloon.

Any clue as to how I could squeeze in a List that displays the multiple addresses?

1

There are 1 best solutions below

3
On

You should implement a custom OverlayItem

public class ListOverlayItem extends OverlayItem {
    private List<Address> list;

    public ListOverlayItem(GeoPoint point, List<Address> list) {
        super(point, "", "");
    }

    public List<Address> getList() {
        return list;
    }
}

then in your custom ItemizedOverlay you can use this list to create a custom dialog with a list in the onTap method

public class ListItemizedOverlay extends ItemizedOverlay<ListOverlayItem> {

    @Override
    protected boolean onTap(int index) {
        // get item they tapped from index
        // use getList() to populate the listview in the custom dialog
    }
}