location_mocker 0.0.1 copy "location_mocker: ^0.0.1" to clipboard
location_mocker: ^0.0.1 copied to clipboard

PlatformAndroid

A comprehensive Flutter plugin for GPS location mocking, route manipulation, and GPX file handling

Stand With Palestine

location_mocker #

A comprehensive Flutter plugin for GPS location mocking, route manipulation, and GPX file handling.

License: MIT Pub Points Pub Version

Why This Package? #

Location Mocker provides a powerful toolset for developers who need to simulate GPS locations and routes in their Flutter applications. Whether you're building navigation apps, fitness trackers, or location-based services, this plugin allows you to:

  • Mock GPS locations on Android devices
  • Play back GPX routes with customizable speeds
  • Plan and manipulate mock routes with deviations
  • Import and export GPX files

Features #

  • πŸ“ GPS Location Mocking: Simulate GPS locations on Android devices
  • πŸ—ΊοΈ GPX Support: Parse, create, and manipulate GPX files
  • βš™οΈ Route Management: Add deviations and modify routes programmatically to simulate real life scenarios
  • πŸ”„ Playback Control: Start, pause, resume, and stop location simulation
  • πŸƒβ€β™‚οΈ Speed Adjustment: Modify the playback speed of simulated routes
  • πŸ“Š Location Streaming: Get real-time updates of the mocked location
  • πŸ’Ύ GPX Export: Export routes to GPX files for sharing or storage

Installation #

dependencies:
  location_mocker: ^0.0.1

Usage #

Initialize the Plugin #

import 'package:location_mocker/location_mocker.dart';

// Initialize the plugin
await LocationMocker.initialize();

// Check if mock location is enabled in developer settings
bool isMockEnabled = await LocationMocker.isMockLocationEnabled();
if (!isMockEnabled) {
  // Open developer settings to enable mock locations
  await LocationMocker.openMockLocationSettings();
}

Mock Locations with a GPX File #

// Start mocking with a GPX file
await LocationMocker.startMockingWithGpxFile('/path/to/route.gpx', 
  playbackSpeed: 1.5); // 1.5x normal speed

// Update playback speed dynamically
await LocationMocker.updatePlaybackSpeed(2.0); // 2x speed

// Pause mocking
await LocationMocker.pauseMocking();

// Resume mocking
await LocationMocker.resumeMocking();

// Stop mocking
await LocationMocker.stopMocking();

Listen to Location Updates #

// Listen to location updates during mocking
LocationMocker.locationStream.listen((GpxPoint point) {
  print('Current location: ${point.latitude}, ${point.longitude}');
  print('Elevation: ${point.elevation}');
  print('Bearing: ${point.bearing}');
});

Route Manipulation #

import 'package:location_mocker/route_manager/route_manager.dart';
import 'package:location_mocker/models/coordinates.dart';

// Create a route manager with a list of coordinates
final routeManager = RouteDeviationManager([
  Coordinates(lat: 37.7749, lng: -122.4194),
  Coordinates(lat: 37.7750, lng: -122.4190),
  // ... more coordinates
]);

// Add a deviation to the route
await routeManager.addDeviation(
  deviationPointIndex: 5,
  deviationLength: 200,  // meters
  deviationDistance: 50, // meters
  skipDistance: 300,     // meters
);

// Export the modified route as a GPX file
String filePath = await routeManager.exportGpxToFile('my_route');

// Reset route to original state
routeManager.resetRoute();

// Get GPX string representation
String gpxString = routeManager.toGpxString;

Parse GPX Data #

// Parse GPX data into a list of points
String gpxContent = '...'; // GPX file content
List<GpxPoint> points = LocationMocker.parseGpx(gpxContent);

for (var point in points) {
  print('Point: ${point.latitude}, ${point.longitude}');
  if (point.elevation != null) {
    print('Elevation: ${point.elevation} meters');
  }
  if (point.time != null) {
    print('Time: ${point.time}');
  }
}

Platform Support #

Currently, this plugin supports the following platforms:

  • βœ… Android
  • ❌ iOS (Due to iOS restrictions on location mocking)

Requirements #

  • Flutter SDK: >= 3.3.0
  • Dart SDK: >= 3.1.5
  • Android: API level 19+ (Android 4.4+)

Permissions #

This plugin requires the following permissions on Android:

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

Limitations #

  • iOS does not support location mocking due to platform restrictions
  • Mock locations require developer mode to be enabled on Android devices
  • Some Android devices might have specific manufacturer restrictions on location mocking

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

0
likes
130
points
106
downloads

Publisher

verified publisheramrahmd.com

Weekly Downloads

A comprehensive Flutter plugin for GPS location mocking, route manipulation, and GPX file handling

Documentation

API reference

License

MIT (license)

Dependencies

downloadsfolder, flutter, http, permission_handler, plugin_platform_interface, retry, xml

More

Packages that depend on location_mocker