πΊοΈ OSM Path Tracker
A simple Flutter package for live GPS tracking , path drawing, and navigation on OpenStreetMap (OSM) using flutter_map
.
osm_path_tracker
helps you track a path in real-time, visualize it, and output a reusable model (PathModel
) so you can store the tracked path wherever you want β Firebase, SQLite, REST APIs, or files.
β¨ Features
- π Real-time GPS tracking with
geolocator
- πΊοΈ OpenStreetMap (OSM) integration using
flutter_map
β Get distance, timestamp, and coordinates in a clean model (PathModel
) - π Automatic distance calculation (in kilometers)
- π Navigate a saved path visually on the OSM map
- πΎ You decide how to store: local DB, Firebase, or any backend!
β¨ Why Use It?
osm_path_tracker
makes live path tracking easy: capture the full journey, visualize it on OpenStreetMap, and store it anywhere β local database, Firebase, or your own server.
Track, draw, and save complete GPS paths β not just A-to-B routes. Own your data and build powerful location features on your terms, with no vendor lock-in.
βοΈ How It Works
1οΈβ£ Live Tracking:
- Use LiveTrackingScreen to track user location in real time.
- It returns a PathModel which contains a tracked path (list of coordinates in form of latitudes and longitudes) with distance and timestamp.
import 'package:latlong2/latlong.dart';
class PathModel {
final List<LatLng> path;
final double distance; // in kilometers
final DateTime timestamp;
}
2οΈβ£ Path Storage:
- The returned PathModel can be stored wherever you like β Firebase, SQLite, or a custom API.
3οΈβ£ Path Navigation:
- Display any saved ( or tracked ) path using PathNavigationScreen.
π Installation
Add the package to your pubspec.yaml
:
dependencies:
osm_path_tracker: ^<latest_version>
Then run in your terminal :
flutter pub get
Check your pubspec.yaml
file whether package is installed properly.
π οΈ Usage
Import the package:
import 'package:osm_path_tracker/osm_path_tracker.dart';
Add Android Permissions
Add these lines to your AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
// add this to enable background location
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
// add this to enable internet
<uses-permission android:name="android.permission.INTERNET"/>
Basic Usage
// Use in your screen and stores path as savedpath from live tracking screen
final result = await Navigator.push(
context,
MaterialPageRoute(builder: (_) => const LiveTrackingScreen()),
);
if (result is PathModel) {
setState(() {
savedPath = result;
});
}
// upload to Firestore
await uploadPathToFirestore(savedPath!);
// upload to Http Server
await uploadPathToHttp(savedPath!, 'https://your-api.com/upload');
Upload to Firestore (Firebase)
Add this helper to your project :
Future<void> uploadPathToFirestore(PathModel path) async {
final firestore = FirebaseFirestore.instance;
final pathData = path.toJson();
await firestore
.collection('paths')
.add(pathData);
print('β
Path uploaded to Firestore!');
}
Upload to HTTP server
Add this helper to your project :
Future<void> uploadPathToHttp(PathModel path, String apiUrl) async {
final response = await http.post(
Uri.parse(apiUrl),
headers: {'Content-Type': 'application/json'},
body: jsonEncode(path.toJson()),
);
if (response.statusCode == 200 || response.statusCode == 201) {
print('β
Path uploaded successfully!');
} else {
throw Exception('β Failed to upload path: ${response.statusCode}');
}
}
See the example app for a complete implementation.
π Documentation
π‘ Contributions
Contributions and issues are welcome!
Please open an issue or submit a pull request.
π License
This project is licensed under the MIT License.