I have an Ionic 2 app which is working fine on Android & IOS. I am now trying to build for Windows and the app is working fine other than I can't use the geolocation features.
I have taken the following steps:
ionic plugin add cordova-plugin-geolocation --save
ionic platform add windows
ionic build windows
Installed the app on a Lumia 650 by using the green Debug
button in VS2015.
I then use this function to get the geolocation:
getUserGeolocation() {
return new Promise((resolve, reject) => {
Geolocation.getCurrentPosition({
timeout: 5000,
enableHighAccuracy: true
}).then(
(res) => {
resolve(res.coords);
},
(err) => {
reject(err);
}
);
});
}
On Windows, this results in an error 'Geolocation access has not been allowed by user.'.
I have gone into the phone settings and checked Privacy > Location
. Everything is enabled in here but my app doesn't show in the list of Choose apps that can use your precise location
. Not sure if this is normal or not.
Does anyone know how to fix this? Thanks for any help.
Edit
Forgot to say that <plugin name="cordova-plugin-geolocation" spec="~2.4.1"/>
is in config.xml
and the plugins in my package.json
look like this:
"cordovaPlugins": [
"ionic-plugin-keyboard",
"cordova-plugin-whitelist",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"cordova-plugin-badge",
"cordova-plugin-app-event",
"cordova-plugin-geolocation",
"cordova-plugin-compat",
"cordova-plugin-globalization",
"cordova-plugin-network-information"
],
Have you added the location
capability to your AppXManifest.xml
file? See How to specify capabilities for more info.
Also note that if your app targets Windows 10 you need to call RequestAccessAsync
before you make any calls and I'm not sure if ionic has been updated to do that.