When making the initial call for geolocation.getCurrentPosition / geolocation.watchPosition user get’s a pop up requesting permission.
However, by the time user approves the pop-up, geolocation.getCurrentPosition returns an error and geolocation.watchPosition simply never fires.
If the user leaves/rejoin the page position is initialized correctly.
However, I can’t see any way to wait for a user response before subscribing/getting the location
code looks like this (in a service):
public startListening(): Observable<Geoposition> {
this.geolocation.getCurrentPosition().then(
(geoPosition: Geoposition) => {
console.log('initial', geoPosition);
this._currentLocation.next(geoPosition);
},
error => {
console.log(error);
this._currentLocation.next(null);
}
);
this.locationSubscription.unsubscribe();
this.locationSubscription = this.geolocation.watchPosition().subscribe(
geoPosition => {
console.log('subscription', geoPosition);
this._currentLocation.next(geoPosition);
},
error => {
console.log(error);
this._currentLocation.next(null);
}
);
return this._currentLocation.asObservable();
}