-1

On Android, Cordova's geolocation plugin consistently takes about 6s to fix a location when other apps return a location instantly most of the time and almost never take more than 2s.

I came across this post Phonegap geolocation sometimes not working on android and removed the geolocation plugin while following the instructions:

cordova plugin rm cordova-plugin-geolocation

To verify that the plugin was removed I ran the app again using ionic run android expecting the following call to fail

var posOptions = {enableHighAccuracy: false, timeout: 10000};

$cordovaGeolocation
    .getCurrentPosition(posOptions)
    .then(function (position) {
        return new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    }, function() {
        $cordovaToast.showLongCenter('Could not get current location. Is GPS Enabled?');
    });

But it's working exactly as before. So I added and removed the android platform thinking the plugin might be cached:

cordova platform rm android
cordova platform add android
cordova plugin list

com.tiltshiftfocus.cordova.plugin.clearCache 1.0.5 "Clear Cache"
cordova-plugin-camera 2.1.0 "Camera"
cordova-plugin-crosswalk-webview 1.5.0 "Crosswalk WebView Engine"
cordova-plugin-device 1.1.0 "Device"
cordova-plugin-file 3.0.0 "File"
cordova-plugin-file-transfer 1.4.0 "File Transfer"
cordova-plugin-statusbar 2.0.0 "StatusBar"
cordova-plugin-whitelist 1.2.1 "Whitelist"
cordova-plugin-x-toast 2.4.0 "Toast"
ionic-plugin-keyboard 1.0.8 "Keyboard"
plugin.google.maps 1.3.9 "phonegap-googlemaps-plugin"

And I also cleared the webview cache just in case

$ionicPlatform.ready(function () {

    window.cache.clear();
    ...
}

But it still runs exactly as before. Why is my app still able to successfully obtain a position from $cordovaGeolocation.getCurrentPosition without the plugin? Is it using the webview's geolocation service as opposed to the plugin? How can I tell which service it's using because I suspect the app wasn't using the plugin to begin with and that this is potentially the cause of the slow gps fix.

I made some text and code changes to the app to see if any changes were being reflected and the new text & code did show up. I even completely uninstalled the app from the device before running ionic run android but the geolocation still works.

Community
  • 1
  • 1
FuzzyTree
  • 30,038
  • 3
  • 46
  • 73

1 Answers1

1

The plugin documentation says

This API is based on the W3C Geolocation API Specification, and only executes on devices that don't already provide an implementation.

Since there are so many Android devices I can not test I just include the plugin to be safe.

As for the 6 seconds vs 2 seconds, it's difficult to assess what other apps are doing without seeing their code. They may be using cached locations or such.

traildex
  • 358
  • 1
  • 4
  • 13
  • 1
    Thanks. It looks like crosswalk provides geolocation services: https://crosswalk-project.org/documentation/cordova/cordova_3/add_plugins.html – FuzzyTree Feb 18 '16 at 20:38