我使用地理定位插件来了解我的ionic2项目中的位置。如果允许位置没有问题。但错误函数调用了两次。这是我的代码
getLocation(){
Geolocation.getCurrentPosition().then((resp) => {
console.log(resp.coords.latitude);
console.log(resp.coords.longitude);
this.options.distance=true;
}).catch((error) => {
console.log('Error getting location', error);
let alert = this.alertCtrl.create({
title: 'Enable Location?',
message: 'Allow Your Location',
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Go to Settings',
handler: () => {
Diagnostic.isLocationAuthorized().then(autherized=>{
if(!autherized){
Diagnostic.switchToLocationSettings();
}
}).catch((error)=>{
console.log(error);
});
}
}
]
});
alert.present();
});
};

提前致谢....