2

I am drawing multiple polygons in my app. I created a touch detection listener (Thanks to matiash : Polygon Touch detection Google Map API V2) But how I know which polygon touched? in the detection listener I'm using polygon.getID() but I couldn't set this ID value. it is random. How can I set the ID.

polygon creation :

            Polygon bol = myMap.addPolygon(new PolygonOptions()
                            .strokeColor(Color.argb(100,255,0,0))
                            .strokeWidth(3)
                            .geodesic(true)
                            .zIndex(1)
                            .clickable(true)
                            .addAll(koords)
            );

and the listener :

    myMap.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {
        @Override
        public void onPolygonClick(Polygon polygon) {
            // Handle click ...
        }
    });
Community
  • 1
  • 1
Ufuk Ugur
  • 186
  • 1
  • 17
  • code required to verify the issue... How are you creating polygon? through code or trying to put marker in map and then based on multiple markers are you drawing? – Sreehari Jan 08 '16 at 10:11
  • the listener gives you the polygon touched as function parameter. The ID is random if you do not assign one when creating the polygon (or later on) – N Dorigatti Jan 08 '16 at 10:38

2 Answers2

1

I found a way to store my polygon ID. I could not modify polygon's ID but it is possible to set a float value of polygon's zIndex.

I'm using integer part of zIndex for polygon's display order and the decimal part of zIndex for my ID value.

For example : 4.12322 4 is display order and 12322 is my ID.

Ufuk Ugur
  • 186
  • 1
  • 17
-1

The simplest solution would be to build your own CustomPolygon class that extends Polygon and add an assignable unique identifier. Then use this class instead of Android's Polygon

nstosic
  • 2,584
  • 1
  • 17
  • 21