# MUBS Background Location

This plugin is currently for internal use in the MUBS project


Update the Info.plist with the following entries

<string>This app needs access to location when open and in the background.</string>
<string>This app needs access to location when in the background.</string>
<string>This app needs access to location when open.</string>

Overwrite the contents of AppDeletage.swift with the following:

import UIKit
import Flutter

import background_locator

func registerPlugins(registry: FlutterPluginRegistry) -> () {
    if (!registry.hasPlugin("BackgroundLocatorPlugin")) {
        GeneratedPluginRegistrant.register(with: registry)

@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)


  LocationManager locationManager = LocationManager.instance;
  Stream<LocationDto> dtoStream;
  StreamSubscription<LocationDto> dtoSubscription;

  void initState() {
    /// Setup Location Manager
    locationManager.distanceFilter = 5;
    locationManager.notificationTitle = 'Mobility Features';
    locationManager.notificationMsg = 'Your geo-location is being tracked';


  void streamInit() async {
    /// Subscribe to stream in case it is already running (Android only, for iOS nothing additional will happen)
    dtoStream = locationManager.dtoStream;
    dtoSubscription = dtoStream.listen(onData);

    // Subscribe if it hasn't been done already 
    if (dtoSubscription != null) dtoSubscription.cancel();

    /// Set up the subscription (again)
    dtoSubscription = dtoStream.listen(onData);
    await locationManager.start();

  void onData(LocationDto dto) {

A LocationDto has the following properties:

final double latitude;
final double longitude;
final double accuracy;
final double altitude;
final double speed;
final double speedAccuracy;
final double heading;
final double time;
final bool isMocked;