geolocation - 我可以在 React Native 上检查设备位置是打开还是关闭

标签 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)
     );
  }
}

最佳答案

我想你可以用

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/

相关文章:

javascript - Cordova 应用程序背景中的GPS坐标

javascript - native react : calling multiple functions onPress

React-Native - TextInput 光标放置在 Android 中的中间而不是顶部

javascript - 从 create react native 弹出后在 android studio 中运行 react native 项目的步骤

javascript - React-native:InputText 事件触发 TouchableHighlight onPress() 事件

android - "npm start"和 "react-native run-android"部署之间有什么区别?

qt - 设置 Qt Location 以从本地 osm 服务器查询

ios - Quickblox:如何删除特定时间段内的用户签到

javascript - 地理定位不适用于手机

ios - Xamarin iOS - CLLocationManager 在后台以设定的时间间隔获取位置