React Native GeoLocation离线模式

时间:2017-06-11 21:36:55

标签: reactjs react-native geolocation react-native-android react-native-ios

React Native地理位置是否在离线模式下工作?我在我的设备上测试并且geolocation.watchPosition效果很好,但是当我转到飞行模式时,我得到了一个位置错误。我打开了我的Google地图应用,可以看到位置仍在跟踪(在飞机模式下)。如何在本地反应中获取地理位置以在脱机模式下工作?如果不可能,有哪些替代方案?

注意:我正在测试IOS,但正在寻找适用于Android和IOS的解决方案。

感谢。

2 个答案:

答案 0 :(得分:0)

  
      
  1. 是的,您可以在离线模式下使用通过使用此代码,它可以在离线模式下使用   非常正确      
        
    • 不要忘记在清单文件中提供位置权限
    •   
    • <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    •   
  2.   
      class GeoLoc extends React.Component{
constructor(props){
    super(props);
    this.state = {
        latitude: null,
        longitude: null,
        error: null,
      };
}

componentDidMount(){
    navigator.geolocation.getCurrentPosition( (position)=>{
        //const ipos = JSON.stringify(Position);
        this.setState({
            latitude: position.coords.latitude,
            longitude: position.coords.longitude,
            error: null,
          });
    },
    (error) => this.setState({ error: error.message }),
    { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
  );
}

render(){
    return(
        <View>
        <Text>Latitude: {this.state.latitude}</Text>
        <Text>Longitude: {this.state.longitude}</Text>
        <Text> {this.state.error} </Text>
       </View> 
    )
}

}

答案 1 :(得分:0)

我试过了 我工作但不总是 即使你没有连接到互联网,它也取决于你的信号 它也取决于你的设备接收信号 在我的情况下,我正在使用asus zenfone 6进行测试,当我连接到互联网时,它运行良好且准确性很好但是当我没有连接到互联网时有时它工作但是确实很差的准确性 在其他情况下,我正在使用三星s7进行测试,当我连接到互联网时,它的工作非常好,准确性非常好,但是当我没有连接到互联网时,有时它工作(工作大多数/多于华硕zenfone 6)但准确性不高

希望能回答你的问题,如果有人建议如何在没有互联网的情况下修复错误的准确性请发表评论

相关问题