gpt4 book ai didi

java - 画 donut 谷歌地图Android

转载 作者:搜寻专家 更新时间:2023-11-01 08:40:45 26 4
gpt4 key购买 nike

我想在谷歌地图上绘制覆盖图,其中除了特定点周围 1.5 公里半径以外的所有内容都被遮蔽了。为此,我尝试使用带有大量边框的圆圈,所以我会在边框中放置透明中心和覆盖颜色来实现这一点,但它无法渲染。

    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

所以我决定使用孔来处理多边形。

    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。

如有任何帮助,我们将不胜感激。

最佳答案

有一个SphericalUtil.computeOffset() Android 中的方法,它返回从指定航向中的原点移动一段距离后得到的 LatLng。

基于您发布的代码的示例代码:

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

enter image description here

关于java - 画 donut 谷歌地图Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32860169/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com