Reputation: 41
someone know how to get event on clik map inside a GeoJsonLayer, follow the code:
here I create a polygon draw in map:
GeoJsonLayer layer = new GeoJsonLayer(googleMap, new JSONObject(myGeoJsonObject.toString()));
I'm able to put markers outside of polygon draw, with this code:
map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
googleMap.addMarker(new MarkerOptions()
.position(latLng)
.title("Hello world"));
}
});
but when I click over draw area the only events trigger are the code below and with this method I can't get Latitude and Longitude.
layer.setOnFeatureClickListener(new GeoJsonLayer.GeoJsonOnFeatureClickListener() {
@Override
public void onFeatureClick(GeoJsonFeature geoJsonFeature) {
try {
System.out.println(geoJsonFeature.getGeometry());
}catch (Exception e) {
e.printStackTrace();
}
}
});
GoogleMap map = layer.getMap();
map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
@Override
public void onPolygonClick(Polygon polygon) {
System.out.println(polygon.getId());
}
});
Thanks.
Upvotes: 3
Views: 683
Reputation: 581
When you are drawing a polygon and you need to put marker or draw another polygon on previously drawn polygon then just simply set the previously drawn polygon to
previousPolygon.setClickable(false);
That's it now you can get the lat lng of the map even if you click over the polygon area. now with the help of lat lng you can draw marker, or another polygon over your previously drawn polygon.
Upvotes: 1