fix: location flow on iOS devices

This commit is contained in:
Rainer Killinger
2023-02-15 18:27:15 +01:00
parent 2f1298c9d7
commit f207e029f1
5 changed files with 95 additions and 22 deletions

View File

@@ -13,7 +13,9 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component} from '@angular/core';
import {MapPosition} from '../../map/position.service';
import {SearchPageComponent} from './search-page.component';
import {Geolocation} from '@capacitor/geolocation';
/**
* Presents a list of places for eating/drinking
@@ -91,4 +93,28 @@ export class FoodDataListComponent extends SearchPageComponent {
];
}
}
async ionViewWillEnter() {
await super.ionViewWillEnter();
this.subscriptions.push(
this.positionService
.watchCurrentLocation(this.constructor.name, {enableHighAccuracy: false, maximumAge: 1000})
.subscribe({
next: (position: MapPosition) => {
this.positionService.position = position;
},
error: async _error => {
this.positionService.position = undefined;
await Geolocation.checkPermissions();
},
}),
);
}
ionViewWillLeave() {
void this.positionService.clearWatcher(this.constructor.name);
for (const sub of this.subscriptions) {
sub.unsubscribe();
}
}
}