watchLocation method doesn't get location in background mode android
See original GitHub issueWhich platform(s) does your issue occur on? Android Android 10 Device Moto G(2nd Generation)
Please, provide the following version numbers that your issue occurs with: CLI: 8.3.18
In, package.json “nativescript-geolocation”: “^5.1.0”,
Please, tell us how to recreate the issue in as much detail as possible.
I’m using Geolocation apis to get location in background in android. When I call watchLocation in foreground, it’s giving location, but when app goes to background, I didn’t get any location. I am displaying location in console.log. For ios, when app goes in background mode, it’s display log of location. I am using nativescript with angular.
Is there any code involved?
public buttonStartTap() {
console.log("buttonStartTap");
try {
let that = this;
this.watchIds.push(geolocation.watchLocation(
function (loc) {
if (loc) {
that.locations.push(loc);
console.log("loc", loc);
}
},
function (e) {
console.log("Error: " + e.message);
},
{
desiredAccuracy: Accuracy.high,
updateDistance: 1,
updateTime: 3000,
minimumUpdateTime: 100,
iosAllowsBackgroundLocationUpdates: true,
iosPausesLocationUpdatesAutomatically: false,
}));
} catch (ex) {
console.log("Error: " + ex.message);
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:15
Top Results From Across the Web
It is possible to watch the location in the background on ...
I have checked it on Chrome (Android M), and as soon as the Web App goes to background the GPS icon disappears and...
Read more >Access location in the background - Android Developers
In your app's manifest, check for the ACCESS_COARSE_LOCATION permission and the ACCESS_FINE_LOCATION permission. Verify that your app requires ...
Read more >Geolocation disabled when Chrome is in the background or ...
It would make sense to reconsider this change and implement watchposition back into Chromium for use in the background. It seems backwards to...
Read more >BackgroundGeolocation | React Native Background Geolocation
ℹ️ You can manually request the current-state of "Power Saving" mode with the method isPowerSaveMode. iOS. iOS Power Saving mode can be engaged...
Read more >Location - Expo Documentation
It's also discouraged to use geocoding while the app is in the background and its results won't be shown to the user immediately....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I found the solution!!! Hopefully, more can test this and confirm.
What I did was I added
android:foregroundServiceType="location"
to my ForegroundService Service in Android.xmlMy final service tag looks like this:
My
minSdkVersion
is 21Hope it helps someone as this was really painful to me… 🤯
I still the same issue, i get only few coordinates after which “service onStopJob” is called