The most recent Google Maps API now includes polylines click listener. You need to be using 8.4+. In gradle file:
compile 'com.google.android.gms:play-services-maps:8.4.0
Setup map polyline listener:
googleMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener()
{
@Override
public void onPolylineClick(Polyline polyline)
{
//do something with polyline
}
});
Polyline needs to be clickable for the listener to work.
PolylineOptions line = new PolylineOptions();
//add path points, set colour, etc. here
Polyline polyline = googleMap.addPolyline(line);
polyline.setClickable(true);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…