绘制甜甜圈谷歌地图Android版 [英] Draw donut google maps Android
问题描述
我想去的地方,除了1.5公里围绕某一点的半径一切阴影了借鉴谷歌地图的覆盖。
我试图用圆,边境此数额巨大,所以我会把透明的中心,覆盖的色彩边境才达到这一点,但它并没有渲染确定。
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));
不过,东经距离而变化,这取决于中锋位置上,所以我得到这样的事情。
http://i.stack.imgur.com/kSXAB.png
这将是完美的,如果它不是椭圆形:)。
我发现这个(jsfiddle.net/doktormolle/NLHf9)JS例如在互联网上,但我不能找到Java函数google.maps.geometry.spherical.computeOffset。
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.
任何帮助将是AP preciated。
Any help would be appreciated.
推荐答案
有一个<一个href=\"http://googlemaps.github.io/android-maps-utils/javadoc/com/google/maps/android/SphericalUtil.html#computeOffset-LatLng-double-double-\"相对=nofollow> SphericalUtil.computeOffset Android中()方法,它返回的经纬度从原点指定标题移动的距离产生的。
There is a SphericalUtil.computeOffset() method in Android, which returns the LatLng resulting from moving a distance from an origin in the specified heading.
样品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; i < 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)));
这篇关于绘制甜甜圈谷歌地图Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!