1
votes

I have an ionic 4 app which uses cordova and the google maps api. I am using the HTML5 geoloction plugin which watches the device 's position as the user moves and then generates a new googleMaps marker and displays it on the map.

this.watchLocation = await this.geolocation
  .watchPosition()
  .subscribe(location => { 
    this.map.animateCamera({
      target: {
        lat: location.coords.latitude,
        lng: location.coords.longitude
      },
      zoom: 16,
      duration: 1000
    });
this.marker.setPosition({
              lat: location.coords.latitude,
              lng: location.coords.longitude
            });

With the code above, i have tested the app on a Samsung note 9 and the results are 100% accurate. I have also tested the same app on other android devices (Galaxy A20 and Huawei Y5) and the results are not accurate, instead the marker jumps out of position for about 50 to 200 meters from my position.

Galaxy note 9 results: enter image description here

1
Have you tried to set the enableHighAccuracy option? See stackoverflow.com/questions/43288402/… - evan
Glad to hear, and you're welcome! Posting this as a full answer then. :) - evan

1 Answers

1
votes

Try setting the enableHighAccuracy option to true. The docs describe it as follows:

The PositionOptions.enableHighAccuracy property is a Boolean that indicates the application would like to receive the best possible results. If true and if the device is able to provide a more accurate position, it will do so. Note that this can result in slower response times or increased power consumption (with a GPS chip on a mobile device for example). On the other hand, if false (the default value), the device can take the liberty to save resources by responding more quickly and/or using less power.

Also refer to related thread Very High Accuracy in Html5 Geolocation