2

I have set Polyline click listener like this :

map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
        public void onPolylineClick(Polyline polyline) {
            int strokeColor = polyline.getColor() ^ 0x0000CC00;
            polyline.setColor(strokeColor);
            Log.e("TAG", "Polyline points @ " + polyline.getPoints());
            Toast.makeText(Draw_Route.this, "Polyline klick: " + polyline.getPoints(), Toast.LENGTH_LONG).show();
        }
    }); 

But i need to get coordinates of that point when user click on polyline, i also used this code to get the codrinates -- >

map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng clickCoords) {
            Log.e("TAG", "Found @ " + clickCoords.latitude + " " + clickCoords.longitude);
        }
    });

But it only works when i click on map, i need to get that point coordinates on click on polyline so please help me, how to get that.

2

use polyline.getPoints(); in your method.

map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() { public void onPolylineClick(Polyline polyline) { int strokeColor = polyline.getColor() ^ 0x0000CC00; polyline.setColor(strokeColor); polyline.getPoints(); Log.e("TAG", "Polyline points @ " + polyline.getPoints()); Toast.makeText(Draw_Route.this, "Polyline klick: " + polyline.getPoints(), Toast.LENGTH_LONG).show(); } });

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.