NativeScript / nativescript-geolocation

Geolocation plugin to use for getting current location, monitor movement, etc
Apache License 2.0
139 stars 77 forks source link

Time interval for watchLocation in iOS #240

Closed ishaqueahmed-mev closed 4 years ago

ishaqueahmed-mev commented 4 years ago

Hello,

I have been using watchLocation method from the plugin to receive the update of location, but it sends updates almost every second or two. I want it to give update every 60 seconds, but I am not getting how to set it, something like updateTime in android, which is ignored in iOS.

Any help would be much appreciated.

Thanks

tbozhikov commented 4 years ago

Hi @ishaqueahmed-mev. Using this plugin at its current state, you cannot call the geolocation.watchLocation() API with a configuration for a guaranteed interval of time between each location updates in iOS. I can suggest you two ways to go to make the refreshes less in number:

  1. Pass larger updateDistance option to the geolocation.watchLocation() API call. This way location updates will be received when more significant changes in the location of the device occur. Read more on distanceFilter in iOS here.
  2. Implement your own custom location watcher using the geolocation.getCurrentLocation() API:

To start watching:

let intervalId = setInterval(() => {
    console.log("Getting current location ...");

    geolocation.getCurrentLocation({
        desiredAccuracy: Accuracy.high,
        maximumAge: 5000,
        timeout: 10000
    }).then(function (loc) {
        if (loc) {
            model.locations.push(loc);
        }
    }, function (e) {
        console.log("Error: " + (e.message || e));
    });
}, 60000); // 1 minute interval

To stop watching:

clearInterval(intervalId);

I hope this helps.

support[bot] commented 4 years ago

:wave: @ishaqueahmed-mev, we use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please, use Stackoverflow to get help.

ishaqueahmed-mev commented 4 years ago

@tbozhikov, thanks for the response. I'll try the second one as I need to receive update every 60 secs, irrespective of location change.

Thanks