I want to implement a touchListener
on a polyline displayed with Google Maps V2 Android API.
Zoom level:
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(lat_Lng, 5);
I tried the following polyline touch 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] < 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
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.
I then changed the aforementioned if
condition from if (results[0] < 100 )
to if (results[0] < 150 * (22 - map.getCameraPosition().zoom))
and the functionality improved but it still does not work all the time.
Note: I want to detect polyline touch at any zoom level.
onMapClickListener
?dispatchTouchEvent
? something else? 2. when you say you want to detect a polyline touch; do you mean a click on the line or would you also like to enable swiping or other touch gestures? – Taffy