I'm using Capacitor for building my Ionic app. I the app I wanna show the current position on a Map via GPS of course.
The following code works and gives me the correct Marker on the Map as I want to, but.. It's far from accurate.
async getLocation() {
var self = this;
let location = await Geolocation.getCurrentPosition({
enableHighAccuracy: true,
timeout: 1000
});
self.marker.setLngLat([location.coords.longitude, location.coords.latitude])
const wait = Geolocation.watchPosition({enableHighAccuracy: true, timeout: 1000}, (position, err) => {
self.marker.setLngLat([position.coords.longitude, position.coords.latitude])
});
}
The Marker is going around like crazy. Happens on every location I test it on. It's moving not centimeters, but meters around my location...
What am I missing that is giving me the less accurate GPS coordinates? I thought enableHighAccuracy: true
was enough, but that's not it.
Positional information can be returned from different location providers: satellite, network, passive. For the best results, you should discard locations provided by network and passive providers.
As far as I know, modern location apis do not differentiate between providers (cf. fused location), but you can always check coords.accuracy
to get an overview of the accuracy of the position.
If the location is triangulated via satellites, accuracy will always be best. Usually below 16 (measured in meters), but definitely below 30. You can safely discard coords with accuracy higher than that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With