Android: Handling both map long press and OverlayItem onTap
<p>I'm writing an application that requires the following:</p>

<ol>
<li>Long press on a map to add some markers, one by one.</li>
<li>After adding a few markers, tap on the first to trigger the drawing of a polygon around all the markers.</li>
</ol>

<p>The following code handles the long press nicely:</p>

<p><a href="http://www.kind-kristiansen.no/2011/android-handling-longpresslongclick-on-map-revisited/" rel="nofollow">http://www.kind-kristiansen.no/2011/android-handling-longpresslongclick-on-map-revisited/</a></p>

<p>For dealing with the markers, I used HelloItemizedOverlay from here:</p>

<p><a href="http://developer.android.com/guide/tutorials/views/hello-mapview.html" rel="nofollow">http://developer.android.com/guide/tutorials/views/hello-mapview.html</a></p>

<p>In the MapActivity I have the following code:</p>

<pre><code>map.setOnLongpressListener(new MyMapView.OnLongpressListener() 
{
  int items = 0;
  public void onLongpress(final com.google.android.maps.MapView view, final com.google.android.maps.GeoPoint longpressLocation) 
  {
    runOnUiThread(new Runnable() 
    {
      public void run() 
      {
        // Insert your longpress action here
        Log.i(TAG,"Long press!");
        OverlayItem clicked = new OverlayItem(longpressLocation, "", "");
        itemizedOverlay.addOverlay(clicked);
        vibrator.vibrate(100);
        if (items == 0)
        {
          mapOverlays.add(itemizedOverlay);
        }
        items++;
      }
    });
  }
});
</code></pre>

<p>In the HelloItemizedOverlay I've overridden onTap, and so can detect both the tap on a marker and the number of markers currently on the map:</p>

<pre><code>private ArrayList&lt;OverlayItem&gt; mOverlays = new ArrayList&lt;OverlayItem&gt;();

@Override
protected boolean onTap(int i) 
{
  // if first marker tapped and 3+ markers on the map
  if (i == 0 &amp;&amp; mOverlays.size() &gt;= 3)
  {
    /*
     * I'd like to draw a polygon around all the points in mOverlays at this point...
     */

  }
  return(true);
}
</code></pre>

<p>So, the question is, where should I put the code to draw the polygon? If it's in the MapActivity, where I'd expect it would have to go, I can't see how to handle the onTap, and if it's in the HelloItemizedOverlay then it's not clear to me how to start drawing on the map when the conditions are met. </p>
