@Override public void onMapClick(LatLng point) { // mTapTextView.setText("tapped, point=" + point); int max = markers.size(); // clear all markers for (int j = 0; j < max; j++) { marker = markers.get(j); marker.setVisible(false); } for (int i = 0; i < max; i++) { polygon = polygons.get(i); polygonPath = polygon.getPoints(); if (PolyUtil.containsLocation(point, polygonPath, false)) { // when click change polygon color polygon.setFillColor(randomColor()); marker = markers.get(i); marker.setVisible(true); marker.showInfoWindow(); break; } // if } // for }
private void readMessage(JsonReader reader) throws IOException { String name = null; String zone = null; String apn = null; String address = null; reader.beginObject(); while (reader.hasNext()) { tag = reader.nextName(); if (tag.equals("name")) { name = reader.nextString(); } else if (tag.equals("zone")) { zone = reader.nextString(); } else if (tag.equals("apn")) { apn = reader.nextString(); } else if (tag.equals("address")) { address = reader.nextString(); } else if (tag.equals("feature") && reader.peek() != JsonToken.NULL) { polygonPath = readLatLngArray(reader); } else { reader.skipValue(); } } // while reader.endObject(); // create new marker and polygon if (address != null && !address.isEmpty()) { address = address + ", COSTA MESA, CA"; } polyopts = new PolygonOptions().addAll(polygonPath); polyopts.fillColor(randomColor()); polyopts.strokeColor(Color.YELLOW); polyopts.strokeWidth(1); polygon = map.addPolygon(polyopts); marker = map.addMarker( new MarkerOptions() .position(polygon.getPoints().get(0)) .title(address) .snippet("APN :[" + apn + "] Zone : (" + zone + ") ") .anchor(0.5f, 0.5f) .infoWindowAnchor(0.5f, 0.5f) .icon(BitmapDescriptorFactory.fromResource(R.drawable.house2))); marker.setVisible(false); }