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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…