Recently, I've been attempting to create a code that will retrieve latitude and longitude from an Ionic-built app. Like many others, I initially used
https://ionicframework.com/docs/native/background-geolocation as my reference for writing the code.
Unfortunately, this plugin proved to be ineffective for me, so I am now seeking alternative methods, with or without using the plugin.
I started off by following the code provided in the Ionic 4 native documentation back in December 2018 when it was functional. However, upon revisiting my app today after some time, I encountered crashes. I attempted rewriting the code and experimenting with different versions of the plugin, but none seemed to 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/