startBackgroundLocation method

void startBackgroundLocation({
  1. int interval = 2000,
  2. double distance = -1,
  3. AMapLocationMode locationMode = AMapLocationMode.Hight_Accuracy,
  4. DesiredAccuracy desiredAccuracy = DesiredAccuracy.Best,
  5. required LocationCallback callback,
})

开启后台进程定位

Implementation

void startBackgroundLocation(
    {int interval = 2000,
    double distance = -1,
    AMapLocationMode locationMode = AMapLocationMode.Hight_Accuracy,
    DesiredAccuracy desiredAccuracy = DesiredAccuracy.Best,
    required LocationCallback callback}) {
  if (backgroundGaodeLocation == null) {
    GaodeLocation? location = GaodeLocation(backgroundService: true);
    location.onLocationChanged().listen((Map<String, Object> result) {
      currentLocation = LocationInfo.fromJson(result);
      callback(currentLocation!);
    });
    backgroundGaodeLocation = location;
  }
  clientMap["xbr_background_time_location"] = backgroundGaodeLocation!;
  LocationOption locationOption = LocationOption(
    onceLocation: false,
    locationInterval: interval,
    distanceFilter: distance,
    locationMode: locationMode,
    desiredAccuracy: desiredAccuracy,
    sensorEnable: true,
  );
  //适配ios14及以上 精准定位权限
  locationOption.fullAccuracyPurposeKey = fullAccuracyPurposeKey ?? "purposeKey";
  backgroundGaodeLocation?.setLocationOption(locationOption);
  backgroundGaodeLocation?.startLocation();
}