0

I need accurate GPS location in my Android app. I am using this Cordova plugin to achieve GPS locations: https://github.com/pmwisdom/cordova-background-geolocation-services

This is the code that requests GPS location:

if (locationClientAPI == null) {
            connectToPlayAPI();
        } else if (locationClientAPI.isConnected()) {
            locationRequest = LocationRequest.create()
                    .setPriority(translateDesiredAccuracy(LocationRequest.PRIORITY_HIGH_ACCURACY))
                    .setFastestInterval(4000)
                    .setInterval(5000)
                    .setSmallestDisplacement(0);

            LocationServices.FusedLocationApi.requestLocationUpdates(locationClientAPI, locationRequest, locationUpdatePI);
            this.isRecording = true;

            if(isDebugging) {
                Log.d(TAG, "- Recorder attached - start recording location updates");
            }
        } else {
            locationClientAPI.connect();
        }

It works an many Android phones, but on some (for example Samsung Galaxy S8) the accuracy is VERY bad. Often 500-1500m which is completely unusable for the app. I have also observed that if I open Google Maps at the same time, the location is also all over the place, UNTIL I start route guidens - then it becomes spot on, almost instantly. And if I use my app, while route guidens is on, everything is very accurate and nice.

In Android settings my app is allowed to use the highest GPS accuracy.

How can I achieve the high accuracy without having to enable route guidance in google maps.

Jolle
  • 1,336
  • 5
  • 24
  • 36

1 Answers1

0

How about this?

var option = {
  enableHighAccuracy: true // use GPS as much as possible
};
plugin.google.maps.LocationService.getMyLocation(option, function(location) {
    var text = ["Current your location:\n",
      "latitude:" + location.latLng.lat.toFixed(3),
      "longitude:" + location.latLng.lng.toFixed(3),
      "speed:" + location.speed,
      "time:" + location.time,
      "bearing:" + location.bearing].join("\n");

    alert(text);
});

https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.0.0/ReleaseNotes/v2.2.0/README.md#locationservicegetmylocation-without-map

wf9a5m75
  • 6,100
  • 3
  • 25
  • 59