简体   繁体   中英

Set marker on Polyline in google maps

I've tried to make possible choice on polyline in google maps. But I'm stuck. For example: I have 10 points (with lines).

by using this part of code:

        polylines = new PolylineOptions();
        polylines.color(getResources().getColor(R.color.poly_line_color));

        //add path points, set colour, etc. here
        polyline = mMap.addPolyline(polylines);
        polyline.setPoints(latLngs);
        polyline.setClickable(true);

        mMap.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
            @Override
            public void onPolylineClick(Polyline polyline) {
                Logger.e("id : "+polyline.getPoints());


            }
        });

we can easy detect click on polyline. But - I can't detect current coordinates (latitude/longitude) for this click.

I tried method

"PolyUtil"

from another library - but this is work randomly and not correct. And really - look like it does not work. 10 clicks on map = 1 good point which is not on polyline or near this line.

Polyline polyline has only few methods and only one normal "getPoints()" but its returned all points.

Can anyone help me with this? I checked a lot of posts on SO but none helped me.

   map.setOnPolylineClickListener(new GoogleMap.OnPolylineClickListener() {
     polyline.getPoints()
});

Try this function polyline.getPoints() in your code. This may help you. Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM