java - Draw donut google maps Android -
i want draw overlay on google maps except radius of 1.5km around point shadowed out. tried use circle huge amount of border this, put transparent center , overlay color in border achive this, 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 showcase
http://i.stack.imgur.com/6nffi.png
so decided 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 = 0; < 360; += 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, this. http://i.stack.imgur.com/ksxab.png perfect if wasn't oval :). found out (jsfiddle.net/doktormolle/nlhf9) js example on internet, can't find function google.maps.geometry.spherical.computeoffset in java.
any appreciated.
there sphericalutil.computeoffset() method in android, returns latlng resulting moving distance origin in specified heading.
sample code based on posted code:
latlng locationsf = new latlng(37.7577, -122.4376); mmap.animatecamera(cameraupdatefactory.newlatlngzoom(new latlng(37.7577, -122.4376), 12)); list<latlng> points = new arraylist<latlng>(); points.add(new latlng(locationsf.latitude-2, locationsf.longitude-2)); points.add(new latlng(locationsf.latitude-2, locationsf.longitude+2)); points.add(new latlng(locationsf.latitude+2, locationsf.longitude+2)); points.add(new latlng(locationsf.latitude+2, locationsf.longitude-2)); list<latlng> hole = new arraylist<latlng>(); float p = 360/360; float d =0; for(int i=0; < 360; ++i, d+=p){ hole.add(sphericalutil.computeoffset(locationsf, 5000, d)); } mmap.addpolygon(new polygonoptions() .addall(points) .addhole(hole) .strokewidth(0) .fillcolor(color.argb(150, 0, 0, 0)));
Comments
Post a Comment