Drawing a polygon all over the map

I am using Google Maps V2 for Android, and I need to draw a polygon all over the map, and then add a hole in the selected city. The purpose of this is to highlight certain areas of the map in accordance with some options.

I tried drawing a polygon all over the map with the following borders:

 Arrays.asList(new LatLng(90, -180),
   new LatLng(-90, -180),
   new LatLng(-90, 180),
   new LatLng(90, 180),
   new LatLng(90, -180));

But the polygon is not drawn into the map. I tried to reduce the borders to a smaller area, and the polygon appears without problems.

How to cover the whole map with a polygon?

+2
source share
3 answers

I have to work with:

float delta = 0.1f;

List points = Arrays.asList(new LatLng(90, -180),

new LatLng(-90+delta, -180+delta),

new LatLng(-90+delta, 0),

new LatLng(-90+delta, 180-delta),

new LatLng(0, 180-delta),

new LatLng(90-delta, 180-delta),

new LatLng(90-delta, 0),

new LatLng(90-delta, -180+delta),

new LatLng(0,-180+delta));

PolygonOptions options = new PolygonOptions();

options.addAll(points);

options.fillColor(R.color.red_half_alpha); // 50% opacity red, for example #80FF0000

map.addPolygon(options);

Hope you see where this code goes. It works great with android v2 card.

, . , (, LatLng (0,180), LatLng (0, -180)), , , .

.

PS: , , . , .

+4

         new PolygonOptions()
        .add(new LatLng(85,90), new LatLng(85,0.1),
             new LatLng(85,-90), new LatLng(85,-179.9),
             new LatLng(0,-179.9), new LatLng(-85,-179.9),
             new LatLng(-85,-90), new LatLng(-85,0.1),
             new LatLng(-85,90), new LatLng(-85,179.9),
             new LatLng(0,179.9), new LatLng(85,179.9))
0

PolygonOptions, , :

List points = Arrays.asList(new LatLng(90, -180),
   new LatLng(-90, -180),
   new LatLng(-90, 180),
   new LatLng(90, 180),
   new LatLng(90, 180));
PolygonOptions options = new PolygonOptions();
options.addAll(points)
options.fillColor(#80FF0000); // 50% opacity red, for example
map.addPolygon(options);

, . , , , :)

-1

Source: https://habr.com/ru/post/1610996/


All Articles