Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic4 watchPosition and getCurrentPosition of Geolocation not accurate with Ionic/Capacitor

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.

like image 552
user1469734 Avatar asked Jun 03 '19 18:06

user1469734


Video Answer


1 Answers

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.

like image 161
Nikitah Avatar answered Oct 05 '22 02:10

Nikitah