搜索插件、代码仓与 APP 分类

插件详情v2.3.2

detect_fake_location

一个用于检测位置是否被模拟或伪造的 Flutter 插件

AndroidiOS
近 30 天下载
2700
喜欢数
41
Pub 分数
140

安装插件

flutter pub add detect_fake_location

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 插件,用于检测设备的位置是否被模拟或伪造。它利用 Android 和 iOS 的平台特定 API 来分析位置数据,以识别欺骗迹象,例如不一致的 GPS 信号或异常移动模式。这有助于应用程序验证用户位置的真实性,从而提高位置敏感型应用的安全性和可靠性。该插件轻量且可无缝集成到现有的 Flutter 项目中。

适合场景

  • 验证共享乘车应用中的用户位置
  • 防止基于地理位置的服务中的欺诈行为
  • 确保健身追踪应用的准确性
  • 保护对地理位置限制内容的访问
  • 检测虚假签到或位置共享

主要特点

  • Android 和 iOS 的跨平台支持
  • 使用原生设备 API 进行精确检测
  • 轻量且易于集成
  • 提供位置伪造的明确指示
  • 最小性能开销

适合对象

  • 需要安全位置验证的应用程序
  • 开发位置感知服务的开发者
  • 具有反欺诈要求的应用程序
  • 使用实时地理定位的移动应用
  • 需要符合位置完整性标准的项目

使用建议

  • 需要适当的位置访问权限
  • 可能无法检测所有高级伪造方法
  • 行为可能在不同设备间略有差异
  • 不是服务器端验证的替代品
  • 在已越狱/越狱设备上的效果有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

detect_fake_location

This is a Flutter plugin that detects if the user is using a fake(mock or simulated) location on their device.

Pub License GitHub code size in bytes

Installation

To use this plugin, add detect_fake_location as a dependency in your pubspec.yaml file.

Permissions

iOS

Add the following entries to your Info.plist file

<key>NSLocationAlwaysUsageDescription</key>
<string>App needs access to location when in the background.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App requires access to location when open.</string>

Add the following to your Podfile

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    # Start of the permission_handler configuration
    target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
        '$(inherited)',
      # dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
        'PERMISSION_LOCATION=1'
    ]
    end
  end
end
Android

Add the ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permission to your Android Manifest.

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

Usage

Import the package with:

import 'package:detect_fake_location/detect_fake_location.dart';

Then you can use the following method to check if the user is using a fake location:

// Basic usage (default behavior)
bool isFakeLocation = await DetectFakeLocation().detectFakeLocation();

// Advanced usage with configuration options
bool isFakeLocation = await DetectFakeLocation().detectFakeLocation(
  ignoreExternalAccessory: true, // Ignore external accessories like CarPlay
);

Configuration Options

ignoreExternalAccessory (iOS only)

By default, the plugin detects fake locations from both software simulation and external accessories. However, external accessories like CarPlay, external GPS devices, or other legitimate hardware can trigger false positives.

  • Default: false (maintains backward compatibility)
  • When to use true: If you want to ignore location data from external accessories and only detect software-based fake locations
  • Use case: Prevent false positives when users have legitimate external accessories connected
// Only detect software-simulated locations, ignore external accessories
bool isFakeLocation = await DetectFakeLocation().detectFakeLocation(
  ignoreExternalAccessory: true,
);

Example

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'My App',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('My App'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            ElevatedButton(
              child: Text('Detect Fake Location (Standard)'),
              onPressed: () async {
                bool isFakeLocation =
                    await DetectFakeLocation().detectFakeLocation();
                _showResult(context, isFakeLocation, 'Standard Mode');
              },
            ),
            SizedBox(height: 20),
            ElevatedButton(
              child: Text('Detect Fake Location (Ignore External Accessory)'),
              onPressed: () async {
                bool isFakeLocation = await DetectFakeLocation()
                    .detectFakeLocation(ignoreExternalAccessory: true);
                _showResult(context, isFakeLocation, 'Ignore External Accessory Mode');
              },
            ),
          ],
        ),
      ),
    );
  }

  void _showResult(BuildContext context, bool isFakeLocation, String mode) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('Fake Location Detection Result'),
          content: Text(
              'Mode: $mode\nThe user is${isFakeLocation ? '' : ' not'} using a fake location.'),
          actions: <Widget>[
            TextButton(
              child: Text('OK'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
        );
      },
    );
  }
}

Image 1 Image 2

Limitations

For iOS, the plugin uses the CLLocationSourceInformation class to detect if the location is simulated by software or produced by an external accessory. This class is only available on iOS 15 or later.

Contribute

Contributions are welcome! Please submit issues and pull requests on the GitHub repository.

Credits

For requesting permissions: permission_handler

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。