HaylLtd / cordova-background-geolocation-plugin

Background and foreground geolocation plugin for Cordova.
Apache License 2.0
56 stars 64 forks source link

How to actively track locations with raw provider? #141

Closed AbdullahSohail-SE closed 1 year ago

AbdullahSohail-SE commented 1 year ago

Describe the bug I tried with the RAW_PROVIDER, it doesn't start tracking locations for some reason unless I have moved away for like 100 to 150 meters (which is quite a lot), with this config,

    locationProvider: BackgroundGeolocation.RAW_PROVIDER,
    desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
    debug: true,
    interval: 1000,
    fastestInterval: 1000,
    activitiesInterval: 1000,

    distanceFilter: 0,

    stopOnStillActivity: false,
    startForeground: true,

    notificationTitle: 'some title',
    notificationText: 'some text',
    notificationIconColor: '#30679a',
    notificationIconSmall: 'app_icon_small',

To Reproduce

Expected behavior Once i call backgroundGeolocation.start(), it should actively track locations in the given interval without any movement or delay and should emit location event after specified interval regardless of movement or not, it works fine on emulator (android 11) but not on the device.

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

HarelM commented 1 year ago

Try distance filter that is not 0.

AbdullahSohail-SE commented 1 year ago

Already tried it, doesn't work, there is no location until i move drastically some 100 meters away, i want the plugin to give location every interval regardless of movement or not :|, just like it does in emulator

AbdullahSohail-SE commented 1 year ago

is there a way so it just continuously emits locations after every interval (1 second) regardless of movement?

AbdullahSohail-SE commented 1 year ago

is there some sort of logic in place so that when you are stationary, the RAW_PROVIDER wont emit locations at all? is there a workaround to this?

HarelM commented 1 year ago

I'm not sure there's a workaround to this, but feel free to look at the raw provider code. Here is my code for reference, 50k users are getting good results with it: https://github.com/IsraelHikingMap/Site/blob/242fe282f19f42542319c36e5becf2af69087f50/IsraelHiking.Web/src/application/services/geo-location.service.ts#L147

AbdullahSohail-SE commented 1 year ago

First of all thanks for providing the code, there are some confusing fields in the configuration though (from the source code given above),

BackgroundGeolocation.configure({
            locationProvider: BackgroundGeolocation.RAW_PROVIDER,
            desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
            stationaryRadius: 10,
            distanceFilter: 5,
            notificationTitle: "Israel Hiking Map",
            notificationText: this.resources.runningInBackground,
            interval: 1000,
            fastestInterval: 1000,
            activitiesInterval: 10000,
            startForeground: true,
            notificationIconLarge: "bg_notification",
            notificationIconSmall: "bg_notification",
        });

According to the API doc, the stationary radius field is relevant when the DIS provider is used, image and so does some other fields like fastestInterval, and activitiesInterval, are they really relevant when the RAW_PROVIDER is used? or do the docs need to be updated?

Secondly, there seems to be a workaround used in the given source code (don't know if it's intended or not), image

any specific reason why the navigator getcurrentposition was used and not the getCurrentLocation of geolocation plugin, are there any good reasons to prefer one over another?

HarelM commented 1 year ago

Regarding the second question: I'm using this code to provide a fast method to see the current location, the raw provider is accurate and can take longer to show the current location, it's a UX decision.

Regarding the parameters, they might not be needed, but I don't want to remove them to see that something breaks, our ability to test that it's working as expected is limited. so, while I don't like this approach in general, in this case: if it ain't broken don't fix it.

AbdullahSohail-SE commented 1 year ago

Thanks for your insights :)