Google Map中PolyGon的点击事件
Clicking event of PolyGon in GoogleMap
我正在尝试制作一个可点击的 PolyGon.Even 我尝试了所有已在此 Whosebug 中回答的方法。但没有任何效果。
我的代码如下,
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();
}
});
非常感谢您的回答。
在将多边形添加到地图之前设置 PolygonOptions.clickable
:
polygonOptions.clickable(true);
googleMap.addPolygon(polygonOptions);
我正在尝试制作一个可点击的 PolyGon.Even 我尝试了所有已在此 Whosebug 中回答的方法。但没有任何效果。 我的代码如下,
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();
}
});
非常感谢您的回答。
在将多边形添加到地图之前设置 PolygonOptions.clickable
:
polygonOptions.clickable(true);
googleMap.addPolygon(polygonOptions);