我正在使用 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 <= GPS_MIN_ACCURACY) {
let position = createPositionObjectFromGeoPosition(geoPosition);
dispatch({type: GPS_UPDATE_LOC, payload: position})
}
}
, (error) => {
console.log(error);
}
, {
enableHighAccuracy: true,
timeout: GPS_TIMEOUT_GET,
maximumAge: GPS_MAX_AGE
});
}, time);
信息列表:
<key>NSLocationAlwaysUsageDescription</key>
<string>Your location is used to track your position during a ride and get feedback (distance ridden, duration, speed, etc) in real time and afterwards.</string>
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
<string>location-services</string>
<string>gps</string>
</array>