Search packages, repositories and app categories

Package detailsv2.0.13

trust_location

A Flutter plugin for detecting mock location on Android device.

Android
30-day downloads
360
Likes
57
Pub points
150

Install package

flutter pub add trust_location

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

TrustLocation is a Flutter plugin designed to detect if a device's location has been mocked on Android. It helps developers verify the authenticity of location data by checking for common signs of location spoofing, such as fake GPS providers or modified location settings. This is particularly useful in applications where accurate geolocation is critical, like ride-sharing, fitness tracking, or security-sensitive services. The plugin integrates seamlessly with Flutter projects and relies on Android-specific system checks to determine trustworthiness.

Use cases

  • Detecting fake GPS in ride-sharing apps
  • Ensuring accurate location in fitness tracking
  • Preventing location spoofing in security apps
  • Validating user location in geofencing
  • Protecting against location-based fraud

Key features

  • Android-only location spoof detection
  • Checks for mock location settings
  • Lightweight and easy to integrate
  • Uses native Android APIs
  • Provides clear trust status result

Suitable for

  • Developers building location-aware Android apps
  • Apps requiring high location accuracy
  • Security-focused mobile applications
  • Services using geofencing or location validation

Considerations

  • Only works on Android devices
  • Requires appropriate permissions
  • Does not detect all spoofing methods
  • Limited to platform-specific implementation
  • May not work on rooted devices

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package

No data available yet.