パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.6.1

background_location_tracker

Android および iOS でバックグラウンド位置を追跡できる Flutter プラグイン

AndroidiOS
30日間ダウンロード
830
いいね数
76
Pub ポイント
150

パッケージをインストール

flutter pub add background_location_tracker

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

AndroidおよびiOSの両方でバックグラウンドでの継続的な位置情報追跡を可能にするFlutterプラグインです。アプリが使用されていない間でもユーザーの位置情報を監視できるため、フィットネス、ナビゲーション、ロジスティクスアプリに最適です。プラグインはプラットフォーム固有の設定と権限を処理し、デバイス間で信頼性の高い動作を保証します。Flutterエコシステムとシームレスに統合され、最小限のバッテリー消費でリアルタイム更新をサポートしています。

用途

  • フィットネストラッキングアプリ
  • 配送および物流モニタリング
  • ジオフェンシングアプリケーション
  • 旅行およびナビゲーションツール
  • 場所ベースのリマインダー

主な機能

  • バックグラウンド位置の更新
  • クロスプラットフォーム対応(Android および iOS)
  • 低消費電力
  • 自動権限処理
  • リアルタイム位置ストリーミング

適している対象

  • 継続的な位置追跡を必要とするアプリ
  • 場所に応じたサービスを開発する開発者
  • 交通または医療分野におけるモバイルアプリケーション

注意事項

  • 明示的なユーザーの許可が必要です
  • デバイスのバッテリー寿命に影響を与える可能性があります
  • プラットフォーム固有のセットアップが必要です
  • プライバシー準拠が必要
  • iOS におけるバックグラウンド実行の制限

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

background_location_tracker

A new Flutter plugin that allows you to track the background location for Android & iOS

Build Status Coverage Status pub package

Android Config

Update compile sdk

Compile sdk should be at 29 at least.

android {
  ...
  compileSdkVersion 29
  ...

  defaultConfig {
    ...
    targetSdkVersion 29
    ...
  }
  ...
}

iOS Configuration

Update Info.plist

Add the correct permission descriptions

	<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
	<string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>
	<key>NSLocationAlwaysUsageDescription</key>
	<string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>
	<key>NSLocationWhenInUseUsageDescription</key>
	<string>Your description why you should use NSLocationAlwaysAndWhenInUseUsageDescription</string>

Add the background location updates in xcode

Or add the info to the Info.plist

	<key>UIBackgroundModes</key>
	<array>
		<string>location</string>
	</array>
Update the AppDelegate
import UIKit
import Flutter
import background_location_tracker

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        GeneratedPluginRegistrant.register(with: self)

        // Register plugins for background execution - this method is deprecated 
        // but kept for backward compatibility
        BackgroundLocationTrackerPlugin.setPluginRegistrantCallback { registry in
            GeneratedPluginRegistrant.register(with: registry)
        }

        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
}

Flutter implementation

Make sure you set the @pragma('vm:entry-point') to make sure you can find the callback in release.

@pragma('vm:entry-point')
void backgroundCallback() {
  BackgroundLocationTrackerManager.handleBackgroundUpdated(
    (data) async => Repo().update(data),
  );
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await BackgroundLocationTrackerManager.initialize(
    backgroundCallback,
    config: const BackgroundLocationTrackerConfig(
      loggingEnabled: true,
      androidConfig: AndroidConfig(
        notificationIcon: 'explore',
        trackingInterval: Duration(seconds: 4),
        distanceFilterMeters: null,
      ),
      iOSConfig: IOSConfig(
        activityType: ActivityType.FITNESS,
        distanceFilterMeters: null,
        restartAfterKill: true,
      ),
    ),
  );

  runApp(MyApp());
}

Future startLocationTracking() async {
  await BackgroundLocationTrackerManager.startTracking();
}

Future stopLocationTracking() async {
  await BackgroundLocationTrackerManager.stopTracking();
}

FAQ:

I get a Unhandled Exception: MissingPluginException(No implementation found for method .... on channel ...)
This is mostly caused by a misconfiguration of the plugin:
- Android: This plugin now uses Flutter's Plugin V2 embedding pattern (FlutterPluginBinding) so you don't need to set a manual plugin registrant callback.
- iOS: For compatibility with older Flutter versions, the setPluginRegistrantCallback is still available but will be removed in a future version.

If you're using Flutter 1.12 or later, the plugin should work out of the box with the V2 embedding.

Migration Guide

Upgrading from older versions

This plugin has been updated to use the modern Flutter Plugin V2 embedding pattern with FlutterPluginBinding. If you're using Flutter 1.12 or later, you don't need to make any changes to your app's code.

For backward compatibility, the older methods are still available but marked as deprecated:

  • BackgroundLocationTrackerPlugin.setPluginRegistrantCallback on Android
  • BackgroundLocationTrackerPlugin.setPluginRegistrantCallback on iOS

These methods will be removed in a future version of the plugin.

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。