Search code examples
androidgoogle-maps-api-2

Dynamically drawing polygons in Google map


I am new to android. I've been trying to apply a field of view to my current location in google map. The image shows a FOV on Google map in iOS.

enter image description here

So basically I did a similar thing by adding 5 triangles with different alpha in order to make the whole fov a gradiant.

enter image description here

I have to update this fov according to azimuth of the device, so I remove those triangles ,recompute them and add them again.

    for(int i=0; i<5;i++){
        if(triangles[i]!=null){
            triangles[i].remove();
        }
    //triangles=null;

        la = mvalues[0]-hang/2;
        lx = lon+i*Math.sin(Math.toRadians(la))/2775;
        ly = lat+i*Math.cos(Math.toRadians(la))/2775;
        ra = mvalues[0]+hang/2;
        rx = lon+i*Math.sin(Math.toRadians(ra))/2775;
        ry = lat+i*Math.cos(Math.toRadians(ra))/2775;

        triangles[i] = map.addPolygon(new PolygonOptions().add(new LatLng(lat,lon), new LatLng(ly,lx), new LatLng(ry,rx)).strokeColor(Color.TRANSPARENT).fillColor(Color.argb(50, 0, 0, 50)));

    }

The fov is always blinking, and gc_concurrent always happens. Is it possible to make it not blinking?

Thanks


Solution

  • https://developers.google.com/maps/documentation/android/shapes

    According to the Google documentation above.

    You shall update the shape by calling Polygon.setPoints Link

    rather than remove/add.

    Hope this would help