Parama Sudha
Parama Sudha

Reputation: 2623

Clicking event of PolyGon in GoogleMap

I am trying to make a clickable PolyGon.Even I tried all the method that have already answered in this StackOverFlow. But nothing is worked. My code is as follows,

JSONObject jsonObj = new JSONObject(result);
                    final JSONArray jsonArray = jsonObj.getJSONArray("zones");
                    int i;

                    System.out.println("PolyGon---> Response   jsonArray " + jsonArray);
                    for (i = 0; i < jsonArray.length(); i++) {
                        JSONArray jsonArrayPoly = jsonArray.getJSONObject(i).getJSONArray("coordinates");
                        System.out.println("PolyGon---> Response   coordinates " + jsonArrayPoly);
                        polygonOptions = new PolygonOptions();
                        polygonOptions.strokeColor(Color.BLACK);
                        polygonOptions.strokeWidth(2);
                        polygonOptions.fillColor(getResources().getColor(R.color.zone));
                        for (int j = 0; j < jsonArrayPoly.length(); j++) {
                            JSONObject jsonCoordinate = jsonArrayPoly.getJSONObject(j);
                            System.out.println("PolyGon---> Response   lat " + jsonCoordinate.getDouble("lat") + " ----> Long");
                            polygonOptions.add(new LatLng(jsonCoordinate.getDouble("lat"), jsonCoordinate.getDouble("lng")));
                        }

                        googleMap.addPolygon(polygonOptions);

                    }

                    polygonOptions.clickable(true);

                    googleMap.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
                        public void onPolygonClick(Polygon polygon) {
                            Toast.makeText(getApplicationContext(), "Problem reading list of markers.", Toast.LENGTH_LONG).show();

                        }
                    });

Your answer is to be more appreciated.

Upvotes: 0

Views: 206

Answers (1)

antonio
antonio

Reputation: 18242

Set your PolygonOptions.clickable before adding your polygon to the map:

polygonOptions.clickable(true);
googleMap.addPolygon(polygonOptions);

Upvotes: 3

Related Questions