【问题标题】:Clicking event of PolyGon in GoogleMapGoogle Map 中 PolyGon 的点击事件
【发布时间】:2016-12-12 07:56:21
【问题描述】:

我正在尝试制作一个可点击的 PolyGon。即使我尝试了此 StackOverFlow 中已经回答的所有方法。但没有任何工作。 我的代码如下,

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();

                        }
                    });

您的回答更值得赞赏。

【问题讨论】:

    标签: android google-maps polygons


    【解决方案1】:

    在将多边形添加到地图之前设置您的PolygonOptions.clickable

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

    【讨论】:

    • 在您发布的代码中polygonOptions.clickable(true);googleMap.addPolygon(polygonOptions); 之后
    • 是的..知道了。谢谢
    猜你喜欢
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 2012-11-21
    • 2012-02-19
    相关资源
    最近更新 更多