反应原生ios:默认情况下,geoloc的准确性很差

我正在使用navigator.geolocation.watchPosition和getCurrentPosition实现健身跟踪器。 它在Android和ios仿真器上工作正常,准确度为5 / 10m,但在iphone 5s上,我的准确度很差(50/65)。

我发现当我在ios上同时运行现有的健身追踪器(strava)时,突然我的应用程序正在非常精确地检索GPS坐标。

很明显,我必须缺少一些配置,因为默认情况下我的应用程序在iOS上使用不高。 知道如何解决这个问题吗?

码:

const GPS_TIMEOUT_GET = 5000; const GPS_MAX_AGE = 1000; const GPS_DISTANCE_FILTER = 5; const GPS_TIMEOUT_WATCH = 60000; const GPS_MIN_ACCURACY = 50; //start the GPS into full time watching. Drains battery but brings best accuracy (required for our needs) let watchId = navigator.geolocation.watchPosition((position) => { } , (error) => { console.log(error); } , { enableHighAccuracy: true, timeout: GPS_TIMEOUT_WATCH, maximumAge: GPS_MAX_AGE, distanceFilter: GPS_DISTANCE_FILTER }); //check GPS every X milliseconds) let intervalId = BackgroundTimer.setInterval(() => { navigator.geolocation.getCurrentPosition((geoPosition) => { if (geoPosition.coords.accuracy  { console.log(error); } , { enableHighAccuracy: true, timeout: GPS_TIMEOUT_GET, maximumAge: GPS_MAX_AGE }); }, time); 

Info.plist的:

 NSLocationAlwaysUsageDescription Your location is used to track your position during a ride and get feedback (distance ridden, duration, speed, etc) in real time and afterwards. UIBackgroundModes  location  UIRequiredDeviceCapabilities  armv7 location-services gps  

我使用https://github.com/timfpark/react-native-location ,它使用iOS本地位置api,并更新了我的代码,以便

  • 在android上,它保持不变并使用已经有效的w3c geolocation api

  • 在iOS上,我开始跟踪上面的iOS专用api,而不是使用w3c geoloc函数’watchPosition’。 为了定期检索位置,来自w3c geoloc的getPosition仍然可以工作(正如我的应用程序同时运行strava时所观察到的那样),所以我保留了它(如果它不满意,可能会重构它以在iOS上完全删除w3c api)。

更新:经过多次用户反馈,我对Android API JS API watchPosition的准确性不满意。 我的应用程序是一个健身追踪器,所以我需要非常高的准确性,但它可能会有所不同。 我建议仔细测试,如果不满意,请使用原生的android API。