React 本机查询 GPS 坐标并给出超时
React native queries GPS coordinates and gives timeout
我们有下一个问题:
我们正在咨询 gps 位置,以便获得仅包含半径接近的列表,但在咨询 GPS 时,它会在等待至少 40 秒后让我们超时。
该问题尤其发生在 Android 小米红米 8 在工业环境中,连接比平时少或在移动中,他们无法始终访问 LTE。
我们使用库@react-native-community / geolocation or navigation.position
您能否帮助我们使用任何其他库或策略来获取 GPS 位置,而这些位置不包含在 gps watching 中,它的位置一直在变化?就像在后台获取它一样..
代码
Geolocation.getCurrentPosition(
position => {
// process the position
},
error => {
console.log(error);
}, {
timeout: 40000,
maximumAge: 0
}
);
引自图书馆的 github 页面:
Currently, on Android, this uses the android.location API. This API is not recommended by Google because it is less accurate and slower than the recommended Google Location Services API. This is something that we want to change in the near future https://github.com/react-native-community/react-native-geolocation/issues/6.
自述文件中还有一些库建议,它们实际上使用了 Google 定位服务 API。我使用了 react-native-location, but this package isn't actively maintained anymore, so I switched to react-native-geolocation-service,它与您已经使用的 API 非常相似,更具体地说是 getCurrentPosition
。
也许你应该试一试。
react-native-community/geolocation 不使用更准确的 Google 定位服务 API,如 readme
中所述
RN Android 的 GPS 定位推荐库(以及我使用的库)是 react-native-geolocation-service。它的自述文件还提到了一个 timeout issue
这让我想知道它是否与您的相同:
This library is created in an attempt to fix the location timeout
issue on android with the react-native's current implementation of
Geolocation API. This library tries to solve the issue by using Google
Play Service's new FusedLocationProviderClient API, which Google
strongly recommends over android's default framework location API. It
automatically decides which provider to use based on your request
configuration and also prompts you to change the location mode if it
doesn't satisfy your current request configuration.
所以如果我是你,我会试一试。 API 旨在替代您使用的库,因此迁移应该只是更改包的问题。
我们有下一个问题: 我们正在咨询 gps 位置,以便获得仅包含半径接近的列表,但在咨询 GPS 时,它会在等待至少 40 秒后让我们超时。 该问题尤其发生在 Android 小米红米 8 在工业环境中,连接比平时少或在移动中,他们无法始终访问 LTE。 我们使用库@react-native-community / geolocation or navigation.position 您能否帮助我们使用任何其他库或策略来获取 GPS 位置,而这些位置不包含在 gps watching 中,它的位置一直在变化?就像在后台获取它一样..
代码
Geolocation.getCurrentPosition(
position => {
// process the position
},
error => {
console.log(error);
}, {
timeout: 40000,
maximumAge: 0
}
);
引自图书馆的 github 页面:
Currently, on Android, this uses the android.location API. This API is not recommended by Google because it is less accurate and slower than the recommended Google Location Services API. This is something that we want to change in the near future https://github.com/react-native-community/react-native-geolocation/issues/6.
自述文件中还有一些库建议,它们实际上使用了 Google 定位服务 API。我使用了 react-native-location, but this package isn't actively maintained anymore, so I switched to react-native-geolocation-service,它与您已经使用的 API 非常相似,更具体地说是 getCurrentPosition
。
也许你应该试一试。
react-native-community/geolocation 不使用更准确的 Google 定位服务 API,如 readme
中所述RN Android 的 GPS 定位推荐库(以及我使用的库)是 react-native-geolocation-service。它的自述文件还提到了一个 timeout issue
这让我想知道它是否与您的相同:
This library is created in an attempt to fix the location timeout issue on android with the react-native's current implementation of Geolocation API. This library tries to solve the issue by using Google Play Service's new FusedLocationProviderClient API, which Google strongly recommends over android's default framework location API. It automatically decides which provider to use based on your request configuration and also prompts you to change the location mode if it doesn't satisfy your current request configuration.
所以如果我是你,我会试一试。 API 旨在替代您使用的库,因此迁移应该只是更改包的问题。