搜尋套件、儲存庫與 APP 分類

套件詳情v2.0.13

trust_location

一個用於檢測 Android 設備上的模擬位置的 Flutter 插件。

Android
近 30 天下載
360
喜歡數
57
Pub 分數
150

安裝套件

flutter pub add trust_location

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

TrustLocation 是一個用於檢測 Android 裝置位置是否被偽造的 Flutter 插件。它幫助開發者透過檢查常見的位置欺騙跡象(如虛假 GPS 提供者或修改的位置設定)來驗證位置資料的真實性。在需要精確地理定位的應用中特別有用,例如計程車共享、健身追蹤或安全敏感服務。該插件可無縫整合到 Flutter 項目中,並依賴 Android 特定的系統檢查來判斷位置的可信度。

適用情境

  • 檢測共乘應用中的虛假GPS
  • 確保健身追蹤中的位置準確
  • 防止安全應用中的位置欺騙
  • 驗證地理圍欄中的用戶位置
  • 防範基於位置的詐欺

主要特色

  • 僅限 Android 的位置偽造檢測
  • 檢查模擬位置設定
  • 輕量且易於整合
  • 使用原生 Android API
  • 提供清晰的信任狀態結果

適合對象

  • 開發位置感知 Android 應用的開發者
  • 需要高精度位置資訊的應用
  • 注重安全的行動應用程式
  • 使用地理圍欄或位置驗證的服務

使用建議

  • 僅適用於 Android 設備
  • 需要適當的權限
  • 無法偵測所有偽造方法
  • 僅限平台特定實作
  • 可能無法在已root的裝置上運作

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Trust Location

A Flutter plugin for detecting mock location on Android device. (Supports only high accuracy location mode) Please enable high accuracy in Android settings before using this plugin. Read more

Installation

Add trust_location as a dependency in your pubspec.yaml file

Permissions

Android

Add either the ACCESS_COARSE_LOCATION or the ACCESS_FINE_LOCATION permission to your Android Manifest. (located under android/app/src/main)

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

NOTE: This plugin uses the AndroidX version of the Android Support Libraries. Detailed instructions can be found here.

Usage

import 'package:trust_location/trust_location.dart';

/* Assuming in an async function */
/// query the current location.
LatLongPosition position = await TrustLocation.getLatLong;

/// check mock location on Android device.
bool isMockLocation = await TrustLocation.isMockLocation;

Using Stream.

// input seconds into parameter for getting location with repeating by timer.
// this example set to 5 seconds.
TrustLocation.start(5);

/// the stream getter where others can listen to.
TrustLocation.onChange.listen((values) =>
    print('${values.latitude} ${values.longitude} ${values.isMockLocation}')
);

/// stop repeating by timer
TrustLocation.stop();

Example

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:trust_location/trust_location.dart';

import 'package:location_permissions/location_permissions.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String? _latitude;
  String? _longitude;
  bool? _isMockLocation;

  /// initialize state.
  @override
  void initState() {
    super.initState();
    requestLocationPermission();
    // input seconds into parameter for getting location with repeating by timer.
    // this example set to 5 seconds.
    TrustLocation.start(5);
    getLocation();
  }

  /// get location method, use a try/catch PlatformException.
  Future<void> getLocation() async {
    try {
      TrustLocation.onChange.listen((values) => setState(() {
            _latitude = values.latitude;
            _longitude = values.longitude;
            _isMockLocation = values.isMockLocation;
          }));
    } on PlatformException catch (e) {
      print('PlatformException $e');
    }
  }

  /// request location permission at runtime.
  void requestLocationPermission() async {
    PermissionStatus permission =
        await LocationPermissions().requestPermissions();
    print('permissions: $permission');
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Trust Location Plugin'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Center(
              child: Column(
            children: <Widget>[
              Text('Mock Location: $_isMockLocation'),
              Text('Latitude: $_latitude, Longitude: $_longitude'),
            ],
          )),
        ),
      ),
    );
  }
}

Credit

Detecting the mock location: LocationAssistant

Issues

Please file any issues, bugs or feature request as an issue on our issues.

Contribute

If you would like to contribute to the plugin, send us your pull request.

License

This plugin is open source project and the license is BSD.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。