Flutter Background Location
Flutter için arka plan konum takibi yapan plugin. Android ve iOS platformlarında çalışır.
Özellikler
- ✅ Arka planda sürekli konum takibi
- ✅ Android Foreground Service desteği
- ✅ iOS Background Location Updates
- ✅ SQLite ile lokal veri saklama
- ✅ API'ye otomatik senkronizasyon
- ✅ Stream tabanlı canlı konum yayını
- ✅ Ayarlanabilir parametreler (interval, distance filter, accuracy)
- ✅ İnternet yokken kuyruk sistemi
Kurulum
pubspec.yaml dosyanıza ekleyin:
dependencies:
arbiter_background_location: ^1.0.0
Kullanım
Temel Kullanım
import 'package:arbiter_background_location/arbiter_background_location.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Plugin'i başlat
await MyBackgroundGeolocation.initialize();
runApp(MyApp());
}
Konum Takibini Başlatma
final config = MyBackgroundGeolocationConfig(
interval: 10000, // 10 saniye
distanceFilter: 50.0, // 50 metre
desiredAccuracy: 'HIGH', // HIGH, BALANCED, LOW
apiUrl: 'https://your-api.com/locations',
userId: 'user123',
headers: {
'Authorization': 'Bearer your-token',
},
);
await MyBackgroundGeolocation.start(config);
Konum Dinleme
MyBackgroundGeolocation.onLocation.listen((location) {
print('Konum: ${location.latitude}, ${location.longitude}');
print('Doğruluk: ${location.accuracy}m');
print('Zaman: ${location.timestamp}');
});
Hata Dinleme
MyBackgroundGeolocation.onError.listen((error) {
print('Hata: $error');
});
Diğer Fonksiyonlar
// Mevcut konumu al
final location = await MyBackgroundGeolocation.getCurrentPosition();
// Kayıtlı konumları getir
final locations = await MyBackgroundGeolocation.getLocations(limit: 100);
// API'ye senkronize et
await MyBackgroundGeolocation.sync('https://api.com/locations');
// Takibi durdur
await MyBackgroundGeolocation.stop();
// Konumları temizle
await MyBackgroundGeolocation.clearLocations();
İzinler
Android
Plugin otomatik olarak gerekli izinleri ekler:
ACCESS_FINE_LOCATIONACCESS_COARSE_LOCATIONACCESS_BACKGROUND_LOCATIONFOREGROUND_SERVICEFOREGROUND_SERVICE_LOCATION
iOS
Info.plist dosyasına otomatik eklenir:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access to location when open and in the background to track your location for delivery and safety purposes.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open to track your location for delivery and safety purposes.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app needs access to location in the background to track your location for delivery and safety purposes.</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
<string>background-processing</string>
</array>
Konfigürasyon
MyBackgroundGeolocationConfig
| Parametre | Tip | Varsayılan | Açıklama |
|---|---|---|---|
interval |
int | 10000 | Güncelleme aralığı (ms) |
distanceFilter |
double | 50.0 | Minimum hareket mesafesi (metre) |
desiredAccuracy |
String | 'HIGH' | Doğruluk seviyesi (HIGH/BALANCED/LOW) |
apiUrl |
String? | null | API URL'si |
userId |
String? | null | Kullanıcı ID'si |
headers |
Map<String, String>? | null | HTTP başlıkları |
LocationData
class LocationData {
final double latitude; // Enlem
final double longitude; // Boylam
final double? accuracy; // Doğruluk (metre)
final double? altitude; // Yükseklik
final double? speed; // Hız (m/s)
final double? heading; // Yön (derece)
final DateTime timestamp; // Zaman damgası
final String? provider; // Sağlayıcı (Android/iOS)
}
Örnek Uygulama
example/ klasöründe tam çalışan bir örnek uygulama bulunmaktadır.
Lisans
MIT License