[英]React Native GeoLocation Offline Mode
Does React Native geo-location work in offline mode? React Native地理位置可以在离线模式下工作吗? I am testing on my device and geolocation.watchPosition works great, but when I flip to airplane mode I get a location error.
我正在我的设备和geolocation.watchPosition上进行测试,但效果很好,但是当我切换到飞行模式时,出现位置错误。 I opened my Google Maps app and can see location is still tracking (in airplane mode) there.
我打开了我的Google Maps应用,可以看到位置仍在跟踪(以飞行模式)。 How can I get geo-location in react native to work in offline mode?
如何在本机React中获取地理位置以在离线模式下工作? If not possible, what are some alternatives?
如果没有可能,还有哪些替代方案?
Note: I am testing on IOS but looking for a solution that will work on both Android and IOS. 注意:我正在IOS上进行测试,但正在寻找一种适用于Android和IOS的解决方案。
Thanks. 谢谢。
- Yes you can use in offline mode By using this code it works in offline mode very correctly
是的,您可以在离线模式下使用通过使用此代码,它可以非常正确地在离线模式下工作
- Don't forget to give location permission in manifest file
不要忘记在清单文件中授予位置权限
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
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>
)
}
} }
i have tried it i works but not always it depends on your signal too even if you do not connect to internet it depends on your device too to receive signal in my case, i am using asus zenfone 6 for a test when i am connected to internet it works well with a good accuracy but when i am not connected to the internet sometimes it work but really bad accuracy in other case, i am using samsung s7 for a test when i am connected to the internet it works really well with a very good accuracy but when i am not connected to the internet sometimes it work(work most/more than asus zenfone 6) but with not good accuracy 我已经尝试了它,但是即使您不连接到互联网,它也不总是取决于您的信号,即使在您连接到互联网的情况下,它也取决于您的设备,我连接到华硕zenfone 6时会进行测试互联网它可以很好地工作,但精度很高,但是当我有时未连接到互联网时,它却可以工作,但在其他情况下却确实精度很差,当我连接到互联网时,我正在使用三星s7进行测试,它可以非常好地工作准确性很高,但是当我未连接到互联网时,它有时可以工作(比华硕zenfone 6最多/更多工作),但准确性不高
hope that answer your question if anyone have a suggestion on how i fix the bad accuracy without internet please leave a comment 希望如果有人对我如何在没有互联网的情况下解决错误的准确性提出建议,请回答您的问题,请发表评论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.