icapps / flutter-background-location-tracker

Flutter background location tracker plugin. (Android / iOS)
MIT License
31 stars 37 forks source link

Feature request: convert all fields of the Location object, not just latitude and longitude #21

Closed slycos closed 1 year ago

slycos commented 3 years ago

Hi,

As can be seen in the log fragment below, LocationUpdatesService receives a full Location object with many fields, but only 'lat' and 'lon' are passed to the Flutter package.

I/flutter (28390): locationUpdate: {lat: 51.508281, lon: -0.1397356, logging_enabled: true}
I/flutter (28390): Location Update: Lat: 51.508281 Lon: -0.1397356
D/BackgroundManager(28390): Got success, destroy engine!
D/LocationUpdatesService(28390): New location: Location[fused 51.508503,-0.139252 hAcc=5 et=+1d9h18m55s853ms alt=72.1 vel=11.020249 bear=39.803856 vAcc=1 sAcc=1 bAcc=30 {Bundle[mParcelledData.dataSize=52]}]

The conversion seems to be happening in the file below and is hard-coded for only lat and lon. Would it be possible to modify it to pass all available Location fields to the Flutter package?

android\src\main\kotlin\com\icapps\background_location_tracker\flutter\FlutterBackgroundManager.kt

private fun handleInitialized(call: MethodCall, result: MethodChannel.Result, ctx: Context, channel: MethodChannel, location: Location, engine: FlutterEngine) {
        val data = mutableMapOf<String, Any>()
        data["lat"] = location.latitude
        data["lon"] = location.longitude
        data["logging_enabled"] = SharedPrefsUtil.isLoggingEnabled(ctx)
        channel.invokeMethod("onLocationUpdate", data, object : MethodChannel.Result {
            override fun success(result: Any?) {
                Logger.debug("BackgroundManager", "Got success, destroy engine!")
                engine.destroy()
            }

            override fun error(errorCode: String?, errorMessage: String?, errorDetails: Any?) {
                Logger.debug("BackgroundManager", "Got error, destroy engine! $errorCode - $errorMessage : $errorDetails")
                engine.destroy()
            }

            override fun notImplemented() {
                Logger.debug("BackgroundManager", "Got not implemented, destroy engine!")
                engine.destroy()
            }
        })
    }

Thank you!

ikbendewilliam commented 3 years ago

Hi, good question. Since we try to keep everything cross platform, we are looking into how it effects the IOS side. I will let you know when/how we decide to implement this.

vanlooverenkoen commented 2 years ago

@slycos thanks for creating this issue. For us this is currently not a high prio. We are accepting pull requests, so if you want to add this for android. and find a good way so iOS is not left out, or it is clear that iOS does not have these values. we will review this pul request.