rfsbraz
rfsbraz

Reputation: 2111

Drawing a polygon over the entire map

I'm using Google Maps V2 for Android, and I need to draw a polygon over the entire map, then add a hole in a selected town. The purpose of this is to highlight specific areas of the map, according to some options.

I tried drawing a polygon over the entire map with the following bounds:

 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 does not get drawn into the map. I tried reducing the bounds to a smaller area and the polygon appears without problems.

How can I cover the entire map with a polygon?

Upvotes: 3

Views: 3749

Answers (3)

Naveedumar
Naveedumar

Reputation: 400

Have a Try using this one

         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))

Upvotes: 7

Christopher
Christopher

Reputation: 73

I should 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);

I hope you see where this code is going. It works fine with a android v2 map.

I think there are some problems with the floating point calculation. The other point is, if you look very carfully between Russia and America (e.g LatLng(0,180), LatLng(0,-180)) you will most likely see a very thin line.

This is your polygon.

PS: If you see holes in your map give a short heads up, how it worked out for you. I think many people have the same problem.

Upvotes: 5

Thibault D.
Thibault D.

Reputation: 10005

Reading PolygonOptions, I think you should be able to do it by:

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);

You have to specify a fill color, if you didn't do it. If you did, sorry, but I cannot guess the code that you haven't posted :)

Upvotes: -1

Related Questions