离子2当前位置在我启动应用程序时不会返回任何位置,然后让用户切换该位置。一旦用户打开GPS并点击重试按钮以获得用户的位置,当前用户位置就会返回任何位置。然而,当gps打开并且我启动时,每件事都有效。
我还会检查位置是否先启用,然后尝试获取当前位置。知道为什么会这样吗?
Diagnostic.isLocationEnabled().then( bool =>{
if( bool == false ){
console.log("location is disbaled")
}
else{
Geolocation.getCurrentPosition(options).then((position) => {
this.usersLocation = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
console.log('user location', this.usersLocation);
}).catch((error) => {
console.log('falling back to deafult user location',
this.usersLocation);
});
}
});