【问题标题】:React Native library to track user locationReact Native 库跟踪用户位置
【发布时间】:2019-07-29 11:39:51
【问题描述】:

哪个库最适合 Android 和 iOS,即使应用在后台运行,也能够持续跟踪用户位置。

我需要跟踪用户的位置以发送通知,告知用户已进入特定位置并且在退出时用户已离开该位置。

【问题讨论】:

  • 听起来你应该使用Geofence。请注意,在更高版本的 Android 8.0 上,如果您的应用在后台运行,则地理围栏事件之间可能会间隔几分钟。这只是 Android 的工作方式,我认为您对此无能为力。

标签: react-native react-native-android react-native-ios react-native-maps


【解决方案1】:

你可以像这样使用地理定位:

 getUserCurrentLocation = async () => {
    return new Promise((resolve, reject) => {
        try {
            navigator.geolocation.getCurrentPosition(position => {
                const { latitude, longitude } = position.coords;
                resolve({ lat: latitude, lng: longitude })
            }, error => {
                console.log(`ERROR(${error.code}): ${error.message}`);
                resolve({ error })
            } // , { enableHighAccuracy: true, timeout: 10000, maximumAge: 1000 }
            );
            setTimeout(() => { resolve({ error: { code: 3 } }) }, 5000);
        } catch (e) {
            resolve({ error: { code: 3 } })
        }
    })
};

【讨论】:

  • @user11426267 如果对您的问题有帮助和解决方案,请将答案标记为正确
  • 什么问题?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-18
  • 2016-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-04
相关资源
最近更新 更多