【发布时间】:2018-07-14 05:47:39
【问题描述】:
我想在没有互联网的情况下获取用户当前位置(仅在 android 中)并通过 SMS 发送。我尝试在本机反应中使用此代码:
navigator.geolocation.getCurrentPosition(
(position) => {
let initialPosition = JSON.stringify(position);
console.log(initialPosition);
},
(error) => console.log(JSON.stringify(error)),
{enableHighAccuracy: true, timeout: 15000, maximumAge: 2000 }
);
但是这段代码给了我这个错误:
error : 3 , Location request timed out
我在谷歌和https://github.com/facebook/react-native/issues/ 搜索这个问题并尝试了很多方法来解决它,像这样:
enableHighAccuracy: false
或 删除选项参数
{enableHighAccuracy: true, timeout: 15000, maximumAge: 2000 }
或
删除maximumAge 和当删除maximumAge 这个工作,但是当删除它
设备给我最后检测到的用户位置,可能远离用户当前位置
也可以试试这个库https://github.com/Agontuk/react-native-geolocation-service 最后一个解决方案并实现库示例代码: https://github.com/Agontuk/react-native-geolocation-service/tree/master/example
但是这段代码只适用于 WIFI,当 WIFI 是给我Time out 错误时。
我的问题是:
如何在没有 GPS 或 Internet 网络的情况下使用 sim 网络检测用户当前位置,在许多 Android 设备和 SDK 版本中都支持?
【问题讨论】:
-
有什么突破吗?
标签: react-native gps