Java 有没有办法在地图框中画出半径为米的圆?

Java 有没有办法在地图框中画出半径为米的圆?,java,android,mapbox,Java,Android,Mapbox,我试图在mapbox中围绕用户当前位置绘制半径为500米的圆。当我使用我在下面提供的代码时,它会画一个大圆圈,并且不会随着地图倾斜 CircleManager circleManager = new CircleManager(mapView, mapboxMap, style); CircleOptions options = new CircleOptions(); options.withLatLng(new LatLng(location.getLatitude(), location.

我试图在mapbox中围绕用户当前位置绘制半径为500米的圆。当我使用我在下面提供的代码时,它会画一个大圆圈,并且不会随着地图倾斜

CircleManager circleManager = new CircleManager(mapView, mapboxMap, style);
CircleOptions options = new CircleOptions();
options.withLatLng(new LatLng(location.getLatitude(), location.getLongitude()));
options.withCircleRadius(500f);
options.withCircleOpacity(0.5f);
options.withCircleColor(ColorUtils.colorToRgbaString(getResources().getColor(R.color.blue2)));

circleManager.create(options);
我希望我的应用程序能像这样工作:

但目前我遇到了这个问题:

已更新

我能用精确的坐标画圆,但我想让这个圆随着我的位置移动。单击地图时会添加圆圈,但从位置更改侦听器调用时无法添加圆圈

private void moveRing(Point centerPoint) {
    if (mapboxMap.getStyle() != null) {
        Style style = mapboxMap.getStyle();

        // Use Turf to calculate the coordinates for the outer ring of the final Polygon
        Polygon outerCirclePolygon = getTurfPolygon(OUTER_CIRCLE_MILE_RADIUS, centerPoint);

        GeoJsonSource outerCircleSource = source;

        if (outerCircleSource != null) {
            outerCircleSource.setGeoJson(Polygon.fromLngLats(outerCirclePolygon.coordinates()));
        }
    }

CircleManager本身不支持此功能,但您可以使用Turf from将所需特性转换为多边形/填充:

  /**
   * Takes a {@link Point} and calculates the circle polygon given a radius in degrees, radians,
   * miles, or kilometers; and steps for precision. This uses the {@link #DEFAULT_STEPS} and
   * {@link TurfConstants#UNIT_DEFAULT} values.
   *
   * @param center a {@link Point} which the circle will center around
   * @param radius the radius of the circle
   * @return a {@link Polygon} which represents the newly created circle
   * @since 3.0.0
   */
  public static Polygon circle(@NonNull Point center, double radius) {
    return circle(center, radius, 64, TurfConstants.UNIT_DEFAULT);
  }

可以将此几何图形与注释插件中的FillManager结合使用

。通过360度的台阶,形成最漂亮的圆圈

这是的Java端口。

@mian asad ali,请参阅。本指南说明了在设备位置更新时可以运行代码<代码>onSuccess()在位置更改时激发。
onSuccess()的内部是可以移动圆的地方。