问题
I'm deploying my Meteor (1.2.0.2) app to an Android device.
I installed the plugin by
meteor add cordova:cordova-plugin-geolocation@1.0.0
Added Cordova plugin cordova-plugin-geolocation@1.0.0.
I used the plugin by:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(function(p){ // onSuccess
console.log(p);
}, function(e){
console.log(e);
});
}
On desktop works perfectly (print p as Geolocation object) but on mobile it just ignores the callbacks (both success and errors).
I tested it in Chrome DevTools (chrome://inspect) by setting breakpoints. It steps until .getCurrentPosition call but then (either step over or step in) just skips both callbacks (and If I set a breakpoint within them, they are just not hit).
I even tried
navigator.geolocation.getCurrentPosition(function(p){ console.log(p);
both on Desktop console (works)
undefined
Geolocation { ... }
and mobile (does not work)
undefined
// nothing else is printed
Maybe has it something to do with app's permissions?
EDIT: I verified AndroidManifest.xml and the permissions are actually set by the plugin:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
回答1:
@dragonmnl,
GPS is unreliable.
You did not talk about timeout, I must assume you have NOT set the timeout long enough. Try setting it to about 20 seconds -- as a minimum.
If your readings are poor, or you are timing out
- go outside
- make sure you have a clear view of all horizons (nothing blocking the view)
- walk in a big circle, about 15ft in diameter
In about 30-45 seconds you should have a reading. This will make sense when you read the link I gave you.
Jesse
来源:https://stackoverflow.com/questions/32995194/meteors-cordova-geolocation-plugin-doesnt-work-on-mobile