How to detect a click on a polyline

后端 未结 3 914
梦毁少年i
梦毁少年i 2020-12-03 17:22

If there is a polyline on googlemap and a click is performed on the map, then how can I check whether that click was on polyline or somewhere else?

Polyline          


        
3条回答
  •  春和景丽
    2020-12-03 18:03

    The solution above doesn't work correctly. Especially if we have large distance between two points of polyline.

    I answered this question: Clickable Polylines Google Maps API Android

    We can modify code above like this:

    mMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
    @Override
    public void onMapClick(LatLng clickCoords) {
            for (PolylineOptions polyline : mPolylines) {
                if (PolyUtil.isLocationOnPath(clickCoords, polyline.getPoints(), true, 100)) {
                    // user clicked on polyline
                }
            }
        }
    });
    

提交回复
热议问题