1

I have about 200 Polylines on my Map. Now i try to find out witch Polyline the User have Click. But polyline.getId() give me every Time a new random number like PL65 next start of the App PL144 and so on.

Is there any Way to know witch Polyline the user have click ? I must show for every Polyline a Text with rules.

   PolylineOptions spss7 = new PolylineOptions() 
       .add(new LatLng(52.260803, 8.16152))
       .add(new LatLng(52.259113, 8.162186))
       .add(new LatLng(52.258438, 8.158634))
       .color(Color.GREEN)
       .geodesic(true);
   Polyline psps7 = googleMap.addPolyline(spss7);
   psps7.setClickable(true);

   PolylineOptions spss8 = new PolylineOptions()  
       .add(new LatLng(52.3524987, 7.709607499999999))
       .add(new LatLng(52.3524921, 7.7098328))
       .add(new LatLng(52.3534915, 7.710031300000001))
       .color(Color.GREEN)
       .geodesic(true);
       Polyline psps8 = googleMap.addPolyline(spss8);
       psps8.setClickable(true);
    }
       googleMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener(){
       public void onPolylineClick(Polyline polyline) {
                   int strokeColor = polyline.getColor() ^ 0x0000CC00;
                   polyline.setColor(strokeColor);
                   Toast.makeText(getActivity(), "Polyline klick: "+polyline.getId(), Toast.LENGTH_LONG).show();
                                                       }
Marcus Berger
  • 67
  • 1
  • 12

1 Answers1

0

You can use the polyline tag to identify the polyline.

           PolylineOptions spss7 = new PolylineOptions() 
           .add(new LatLng(52.260803, 8.16152))
           .add(new LatLng(52.259113, 8.162186))
           .add(new LatLng(52.258438, 8.158634))
           .color(Color.GREEN)
           .geodesic(true);
       Polyline psps7 = googleMap.addPolyline(spss7);
       psps7.setClickable(true);
       psps7.setTag(new String("psps7"));

       PolylineOptions spss8 = new PolylineOptions()  
           .add(new LatLng(52.3524987, 7.709607499999999))
           .add(new LatLng(52.3524921, 7.7098328))
           .add(new LatLng(52.3534915, 7.710031300000001))
           .color(Color.GREEN)
           .geodesic(true);
           Polyline psps8 = googleMap.addPolyline(spss8);
           psps8.setClickable(true);
           psps8.setTag(new String("psps8"));
        }
           googleMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener(){
           public void onPolylineClick(Polyline polyline) {
                       int strokeColor = polyline.getColor() ^ 0x0000CC00;
                       polyline.setColor(strokeColor);
                       Toast.makeText(getActivity(), "Polyline klick: " +
                       (String)polyline.getTag(), Toast.LENGTH_LONG).show();
                                                           }

We set the tag for the 2 polylines in this example then in the onClickListener we get the tag and cast it back to a string.

GonzoCSU
  • 1
  • 2