Android Capacitor geolocation not updating on getCurrentPosition
See original GitHub issueDescription of the problem:
I have two methods in my component for getting geolocation, one with capacitor, one with html5/js. The method with html5/js returns a new location each time I call it, the capacitor one does not, it either returns no location or the same location each time. There seems to be a correlation, if I get the location with html5 or even switch to another app that gets location, then the capacitor location will update, but subsequent calls will return the same coordinates/accuracy over an over, even if I move.
Affected platform
- Android
OS of the development machine
- Windows
Other information: Ionic/Angular 4.0.1
Testing on device with ‘ionic build’, ‘npx cap sync android’ and ‘npx cap open android’ debugging via android studio on samsung galaxy s7.
Capacitor version: 1.0.0-beta.17
node version: v10.15.0,
npm version: 6.4.1
Steps to reproduce:
async getCurrentPosition() {
const { Geolocation } = Plugins;
Geolocation.getCurrentPosition({timeout: 30000, enableHighAccuracy: true}).then(position => {
this.position = position;
}, error => console.log(error));
}
getCurrentPostionNavigator() {
navigator.geolocation.getCurrentPosition((position) => {
this.navPosition = position;
}, err => {
console.error(err);
this.navPositionErr = `${err.code} ${err.message}`;
}, { timeout: 30000, enableHighAccuracy: true });
}
<ion-card>
<ion-card-header>Capacitor Location</ion-card-header>
<ion-card-content>
<ion-button (click)="getCurrentPosition()">Get Position</ion-button>
<div *ngIf="position">
Lat: {{position.coords.latitude}}<br />
Lng: {{position.coords.longitude}}<br />
Accuracy: {{position.coords.accuracy}}
</div>
<span *ngIf="positionErr">{{positionErr}}</span>
</ion-card-content>
</ion-card>
<ion-card>
<ion-card-header>HTML5 Location</ion-card-header>
<ion-card-content>
<ion-button (click)="getCurrentPostionNavigator()">Get Position</ion-button>
<div *ngIf="navPosition">
Lat: {{navPosition.coords.latitude}}<br />
Lng: {{navPosition.coords.longitude}}<br />
Accuracy: {{navPosition.coords.accuracy}}
</div>
<span *ngIf="navPositionErr">{{navPositionErr}}</span>
</ion-card-content>
</ion-card>
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:12 (3 by maintainers)
Top GitHub Comments
@coffeymatt Is your example code working on a real Android device? I tried it multiple times now and watchPosition() is simply not working on Android for me. I also did set the timeout to 10000, but it never stops loading. Are you sure that this number is miliseconds? The documentation is unfortunately not saying anything about the dimensional unit.
@REPTILEHAUS Since this isn’t working on Android at all for me I guess the simulator should show the exact same behavior.
@jcesarmobile I am very sorry to ask, but if on Android getCurrentPosition() isn’t returning the current position, watchPosition() isn’t working at all and “Fused Location Provider” is planned for 2.0… is there any other option to solve this issue right now? Thank you very much for your feedback, really appreciate that.
@ChariereFiedler Unfortunately not yet. getCurrentPosition() is somehow getting the geo position, but not the current one and only the last requested one by Google Maps for example, no matter which options I choose.