addPoiGeoFence method

Stream<GeoFenceEvent> addPoiGeoFence({
  1. required String keyword,
  2. String poiType = '',
  3. String city = '',
  4. int aroundRadius = 10,
  5. String customId = '',
  6. List<GeoFenceActiveAction> activeActions = const [GeoFenceActiveAction.In, GeoFenceActiveAction.Out, GeoFenceActiveAction.Stayed],
})

创POI电子围栏

Implementation

Stream<GeoFenceEvent> addPoiGeoFence({
  required String keyword,
  String poiType = '',
  String city = '',
  int aroundRadius = 10,
  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?.addPoiGeoFence(
      keyword: keyword,
      poiType: poiType,
      city: city,
      aroundRadius: aroundRadius,
      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
        ?.addKeywordPOIRegionForMonitoringWithKeyword_POIType_city_size_customID(
      keyword,
      poiType,
      city,
      aroundRadius,
      customId,
    );
  } else {
    throw '未实现的平台';
  }

  yield* _geoFenceEventController!.stream;
}