我正在用navigator.geolocation.watchPosition和getCurrentPosition实现一个健身跟踪器。它在android和ios模拟器上运行得很好,有5/10米的精度,但在iPhone5S上,我的准确率很高(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);Info.plist:
<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>发布于 2017-04-26 15:55:36
我使用了https://github.com/timfpark/react-native-location,它使用iOS本机位置api,并更新了我的代码,以便
更新:经过很多用户反馈后,我对安卓上JS的准确性并不满意。我的应用是一个健身跟踪,所以我需要非常高的准确性,但它可能是不同的,以您的需要。我建议对它进行仔细的测试,如果不能令人满意的话,使用原生的android代替。
https://stackoverflow.com/questions/43629524
复制相似问题