Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid itemizedOverlay's onTap action overrided
    primarykey
    data
    text
    <p>I have a class :</p> <pre><code>class MapItemizedOverlay extends com.google.android.maps.ItemizedOverlay&lt;OverlayItem&gt; { private Context context; private ArrayList items = new ArrayList(); public MapItemizedOverlay(Context aContext, Drawable marker) { super(boundCenterBottom(marker)); context = aContext; } public void addOverlayItem(OverlayItem item) { items.add(item); populate(); } @Override protected OverlayItem createItem(int i) { return (OverlayItem) items.get(i); } @Override public int size() { return items.size(); } @Override protected boolean onTap(int index) { OverlayItem item = (OverlayItem) items.get(index); AlertDialog.Builder dialog = new AlertDialog.Builder(context); dialog.setTitle(item.getTitle()); dialog.setMessage(item.getSnippet()); dialog.show(); return true; } @Override public boolean onTap (final GeoPoint p, final MapView mapView) { Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault()); try { List&lt;Address&gt; addresses = geoCoder.getFromLocation(p.getLatitudeE6() / 1E6, p.getLongitudeE6() / 1E6, 1); String address = ""; if (addresses.size() &gt; 0) { for (int i=0; i&lt;addresses.get(0).getMaxAddressLineIndex(); i++) address += addresses.get(0).getAddressLine(i) + "\n"; } address.cancel(); address.setText(address); address.show(); } catch (IOException e) { e.printStackTrace(); } return true; } } </code></pre> <p>I add some overlays on the map with the function:</p> <pre><code>private void initialiseOverlays() { // Create an ItemizedOverlay to display a list of markers Drawable defaultMarker = getResources().getDrawable(R.drawable.marker); MapItemizedOverlay mapItemizedOverlay = new MapItemizedOverlay(this, defaultMarker); mapItemizedOverlay.addOverlayItem(new OverlayItem(new GeoPoint((int) (12.345678 * 1E6), (int) (23.456789 * 1E6)), "Point 1", "some-random-text")); mapItemizedOverlay.addOverlayItem(new OverlayItem(new GeoPoint((int) (89.012345 * 1E6), (int) (67.890123 * 1E6)), "Point number 2", "more-random-text")); // Add the overlays to the map mapView.getOverlays().add(mapItemizedOverlay); } </code></pre> <p>If only one of the onTap functions is defined everything works fine - I can either get the address if I click somewhere over the map or I can get a dialog with the place's title and content if I click on the icon over the place. But I want to have both of the functions working together, the application to detect if the click was over an empty place on the map or over a marker(the drawable set) and show it's information. How can I achieve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload