Feature/improvements #1
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Não revise, ainda estou implementando melhorias
Background Location Plugin
A Flutter plugin for getting location updates in the background on Android and iOS. This plugin provides a simple way to get location updates even when the app is in the background.
Features
Installation
Add this to your package's
pubspec.yaml
file:Android Setup
Add the following permissions to your
android/app/src/main/AndroidManifest.xml
file:Also, make sure your
android/app/build.gradle
has the minimum SDK version set to 21 or higher:iOS Setup
Add the following keys to your
ios/Runner/Info.plist
file:Usage
Here's a simple example of how to use the plugin:
Error Handling
The plugin provides error handling through try-catch blocks and error callbacks:
Location Data Caching
The plugin automatically caches the last known location. You can access it using:
Configuring Accuracy
You can configure the location accuracy when starting the service:
API Reference
Methods
startLocationService({LocationAccuracy accuracy = LocationAccuracy.high})
: Starts the location servicestopLocationService()
: Stops the location serviceisLocationServiceRunning()
: Checks if the location service is runningrequestPermissions()
: Requests location permissionscheckPermissions()
: Checks if location permissions are grantedgetLastKnownLocation()
: Gets the last known location from cacheStream
locationStream
: A stream ofLocationData
objects containing:latitude
: The latitude of the locationlongitude
: The longitude of the locationaccuracy
: The accuracy of the location in metersaltitude
: The altitude of the location in metersspeed
: The speed of the device in meters per secondspeedAccuracy
: The accuracy of the speed in meters per secondheading
: The heading of the device in degreestime
: The timestamp of the location updateTroubleshooting
Common Issues
Location updates not working in background
High battery consumption
Permission issues
Debug Mode
Enable debug mode to get detailed logs:
Example App
Check out the example directory for a complete implementation.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
This project is licensed under the MIT License - see the LICENSE file for details.