Reputation: 81
For a while, I have been trying to write a code to get lat long from an App build in Ionic. Like most Users, I used
https://ionicframework.com/docs/native/background-geolocation to write the code.
This plugin does not work, I'm looking for the best way with our without using the plugin.
What I already did was finished using the code from ionic 4 native documentation, In December 2018 it worked. I opened my app today after a while. The app crashed, I re-wrote the code. tried different versions of the plugin but to no avail, they do not work.
setBackgroundTracking(){
this.backgroundGeolocation.configure(config)
.then(() => {
this.backgroundGeolocation.on('location').subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
// IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
// and the background-task may be completed. You must do this regardless if your operations are successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
this.backgroundGeolocation.finish(); // FOR IOS ONLY
});
});
The above code is an exact copy paste from the documentation. and the code is buggy.
Property 'subscribe' does not exist on type 'Promise<any>'.ts(2339)
If you guys can fix the code or tell me another way to do it, please let me know. I have just been brainstorming would appreciate input/
Upvotes: 1
Views: 222
Reputation: 11000
Seems you failed to copy/paste from documentation:
this.backgroundGeolocation.configure(config)
.then(() => {
this.backgroundGeolocation.on('location').subscribe((location: BackgroundGeolocationResponse) => {
console.log(location);
Upvotes: 1