我可以在使用前检查设备位置是打开还是关闭geolocation
?
我想显示类似 App need to run your location, please open your devices location
的警报消息, 当设备位置接近时。
我可以导航到本地位置设置 IOS 和 Android 吗?
比如例子——
componentDidMount() {
// Check condition device location is open or close.
if( DevicesLocation === 'close' ) {
alert('App need to run your location, please open your devices location');
// other process
} else {
navigator.geolocation.getCurrentPosition(
(position) => {
var initialPosition = JSON.stringify(position);
this.setState({ initialPosition});
},
(error) => console.log(error.message)
);
}
}
最佳答案
我想你可以用
navigator.geolocation.getCurrentPosition(
(position) => {
//do stuff with location
},
(error) => {
this.setState({locationEnabled: false}),
},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);
对于从您的应用程序打开设置,我认为您将不得不使用 native 代码:D
关于geolocation - 我可以在 React Native 上检查设备位置是打开还是关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38471794/