title: Touch detection on polyline in Google Maps Android API v2
body: <p>I want to implement a <code>touchListener</code> on a polyline displayed with Google Maps V2 Android API. </p>
  
  <p>Zoom level:
  <code>CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(lat_Lng, 5);</code></p>
  
  <p>I tried the following polyline touch code:</p>
  
  <pre><code>boolean onpoly = false;
              for (Polyline polyline : mPolylines) {
                  for (LatLng polyCoords : polyline.getPoints()) {
                      float[] results = new float[1];
  
                      Location.distanceBetween(points.latitude, points.longitude, polyCoords.latitude, polyCoords.longitude, results);
  
                      if (results[0] &lt; 100 ) {
                          onpoly = true;
  
                          Marker mark = map.addMarker(new MarkerOptions().position(points).title("AddEvent")
  
                          .snippet("" + addressaddexpense).icon(BitmapDescriptorFactory.fromResource(R.drawable.addicon)));
  
                          UtilsClass.dropPinEffect(mark);
                      }// end if..
                  } // end for loop
              }// end for loop
  
              if (onpoly == true) {
                  Toast.makeText(getActivity(), "Poly line detected", Toast.LENGTH_SHORT).show();
              }// end if
  </code></pre>
  
  <p>It worked but not perfectly. 
  it will not detect the touch event unless i zoom in, sometimes forcing me to tap the map more than 5 times before zooming to achieve detection.</p>
  
  <p>I then changed the aforementioned <code>if</code> condition from <code>if (results[0] &lt; 100 )</code> to <code>if (results[0] &lt; 150 * (22 - map.getCameraPosition().zoom))</code> and the functionality improved but it still does not work all the time.</p>
  
  <p><em>Note:</em> I want to detect polyline touch at any zoom level.</p>