addCircleGeoFence method

Stream<GeoFenceEvent> addCircleGeoFence({
  1. required LatLng center,
  2. required double radius,
  3. String customId = '',
  4. List<GeoFenceActiveAction> activeActions = const [GeoFenceActiveAction.In, GeoFenceActiveAction.Out, GeoFenceActiveAction.Stayed],
})

创建圆形电子围栏

Implementation

Stream<GeoFenceEvent> addCircleGeoFence({
  required LatLng center,
  required double radius,
  String customId = '',
  List<GeoFenceActiveAction> activeActions = const [
    GeoFenceActiveAction.In,
    GeoFenceActiveAction.Out,
    GeoFenceActiveAction.Stayed,
  ],
}) async* {
  _geoFenceEventController ??= StreamController<GeoFenceEvent>.broadcast();

  if (Platform.isAndroid) {
    final context = await android_app_Application.get();
    _androidGeoFenceClient ??= await com_amap_api_fence_GeoFenceClient
        .create__android_content_Context(context);

    final point = await com_amap_api_location_DPoint.create__double__double(
        center.latitude, center.longitude);

    await _androidGeoFenceClient?.addCircleGeoFence(
      activeActions.getActiveAction(),
      point,
      radius,
      customId,
    );
  } else if (Platform.isIOS) {
    _iosGeoFenceClient ??= await AMapGeoFenceManager.create__();

    _iosGeoFenceDelegate ??= await AMapGeoFenceManagerDelegate.anonymous__();
    _iosGeoFenceDelegate!
            .amapGeoFenceManager_didGeoFencesStatusChangedForRegion_customID_error =
        (_, region, customId, error) async {
      final status = await region!.get_fenceStatus();
      _geoFenceEventController?.add(
        GeoFenceEvent(
          customId: customId,
          fenceId: await region.get_identifier(),
          status: GeoFenceStatusX.fromIOS(status!),
          genFence: GeoFence.ios(region),
        ),
      );
    };
    _iosGeoFenceClient!.set_delegate(_iosGeoFenceDelegate!);

    await _iosGeoFenceClient
        ?.set_activeActionX(activeActions.getActiveAction());

    await _iosGeoFenceClient?.set_allowsBackgroundLocationUpdates(true);

    final point = await CLLocationCoordinate2D.create(
      center.latitude,
      center.longitude,
    );

    await _iosGeoFenceClient
        ?.addCircleRegionForMonitoringWithCenter_radius_customID(
            point, radius, customId);
  } else {
    throw '未实现的平台';
  }

  yield* _geoFenceEventController!.stream;
}