Lwi*_*yat 7 geolocation react-native
我可以在使用之前检查设备位置是打开还是关闭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)
);
}
}
Run Code Online (Sandbox Code Playgroud)
我想你可以用
navigator.geolocation.getCurrentPosition(
(position) => {
//do stuff with location
},
(error) => {
this.setState({locationEnabled: false}),
},
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
);Run Code Online (Sandbox Code Playgroud)
要从您的应用程序打开设置,我认为您必须亲自使用本机代码:D
| 归档时间: |
|
| 查看次数: |
2457 次 |
| 最近记录: |