In IOS there isn't a problem while looking for gps coords. It works fine.
On Android side its not stable as IOS. This problem both in real device and emulator. Sometimes it can find location, but sometimes not. Looking for 3days but there wasn't find a solution.
When my app cannot find my location, I tried via Google Maps app, it works like charm.
Here is my code for both IOS and Android;
getCurrentPosition() {
navigator.geolocation.getCurrentPosition(
(position) => {
this.setState({ initialPosition: position });
alert(JSON.stringify(position))
var coords = new Coords();
coords.Latitude = position.coords.latitude;
coords.Longitude = position.coords.longitude;
this.getPharmaciesByCoordinates(coords);
},
(error) => alert(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
this.watchID = navigator.geolocation.watchPosition((position) => {
this.setState({ initialPosition: position });
},
(error) => alert(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
}
Any kind of solution is welcome.
Thanks
I removed maximumAge: 3600000
on Android and it working