I want to draw overlay on google maps where everything except radius of 1.5km around certain point is shadowed out. I tried to use circle with huge amount of border for this, so i would put transparent center and overlay color in border to achive this, but it doesn't render OK.
map.addCircle(new CircleOptions()
.center(london)
.radius(500)
.strokeWidth(100)
.strokeColor(R.color.map_overlay_color)
.fillColor(Color.RED)); // not transparent for showcase
http://i.stack.imgur.com/6NFfI.png
So i decided to do it with polygon using hole.
List<LatLng> points = new ArrayList<LatLng>();
points.add(new LatLng(london.latitude-2, london.longitude-2));
points.add(new LatLng(london.latitude-2, london.longitude+2));
points.add(new LatLng(london.latitude + 2, london.longitude + 2));
points.add(new LatLng(london.latitude + 2, london.longitude - 2));
List<LatLng> hole = new ArrayList<LatLng>();
for(int i = 0; i < 360; i += 1){
LatLng coords = new LatLng(london.latitude + (radius * Math.cos(Math.toRadians(i))), london.longitude + (radius * Math.sin(Math.toRadians(i))));
hole.add(coords);
Log.d("HOLE", coords.toString());
}
map.addPolygon(new PolygonOptions()
.addAll(points)
.addHole(hole)
.strokeWidth(0)
.fillColor(R.color.map_overlay_color));
But longtitude distance varies, depending on center position, so i get something like this. http://i.stack.imgur.com/kSXAB.png Which would be perfect if it wasn't oval :). I found out this (jsfiddle.net/doktormolle/NLHf9) JS example on the internet, but i can't find function google.maps.geometry.spherical.computeOffset in java.
Any help would be appreciated.
There is a SphericalUtil.computeOffset() method in Android, which returns the LatLng resulting from moving a distance from an origin in the specified heading.
Sample code based on your posted code: