搜索插件、代码仓与 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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。