Clickable List in OverlayItem (MapView for Android)

I have a map view with several contacts printed on different addresses. Everything works very well. The problem occurs when you have multiple elements pointing to the same address. For instance,

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

I use the following line of code to extract lat and long to create a GeoPoint.

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

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

According to the API, the two addresses mentioned above return the same coordinates.

Thus, when constructing the pins on the map, they rewrite each other, ending with one output for several addresses.

I tried to implement a list displaying all duplicate addresses in a balloon. The attempt was in vain, and I realized that

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

Allows me to only specify two lines to be shown on the balloon.

Any hint on how I could compress in a list that displays multiple addresses?

+4
source share
1 answer

You must implement 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 the 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 } } 
0
source

Source: https://habr.com/ru/post/1381407/


All Articles