Search code examples
androidgoogle-mapsgoogle-maps-markersgoogle-polyline

How to keep state for polygons?


I was reading the documentation for polygons and polylines What is not clear to me is how could I keep a state associated with a polygon?
E.g. if I want to do an action on click that depends on whether the polygon was already clicked on or not how could I know that?
Could I use e.g. tag to add arbitrary info including if the polygon is in click/state?


Solution

  • you can use setTag() with custom object which include click state and other data like

    CustomDefinedObject data = new CustomDefinedObject ();// your defined object
    data.isClicked=true
    data.otherProperty=false
    polyline.setTag(data);
    

    and to retrieve info

    CustomDefinedObject retrievedData = (CustomDefinedObject)polyline.getTag(data);