addDistrictGeoFence method

Stream<GeoFenceEvent> addDistrictGeoFence({
  1. required String keyword,
  2. String customId = '',
  3. List<GeoFenceActiveAction> activeActions = const [GeoFenceActiveAction.In, GeoFenceActiveAction.Out, GeoFenceActiveAction.Stayed],
})

创建行政区划电子围栏

Implementation

Stream<GeoFenceEvent> addDistrictGeoFence({
  required String keyword,
  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);

    await _androidGeoFenceClient?.addDistrictGeoFence(
      keyword: keyword,
      customId: customId,
      activeAction: activeActions.getActiveAction(),
    );
  } else if (Platform.isIOS) {
    _iosGeoFenceClient ??= await AMapGeoFenceManager.create__();
    _iosGeoFenceDelegate ??= await AMapGeoFenceManagerDelegate.anonymous__();

    await _iosGeoFenceClient?.set_delegate(
      _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),
            ),
          );
        },
    );

    await _iosGeoFenceClient
        ?.set_activeActionX(activeActions.getActiveAction());
    await _iosGeoFenceClient?.set_allowsBackgroundLocationUpdates(true);
    await _iosGeoFenceClient
        ?.addDistrictRegionForMonitoringWithDistrictName_customID(
            keyword, customId);
  } else {
    throw '未实现的平台';
  }

  yield* _geoFenceEventController!.stream;
}