Appcelerator Geolocation 从不 returns iOS 速度

Appcelerator Geolocation never returns a speed on iOS

我正在使用 Appcelerator 提供地理跟踪。这在 Android 上运行良好,但在 iOS 平台上我无法从 onLocation 事件中获取速度或航向信息。

我初始化我的 GPS:

permissions.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_ALWAYS, function (e) {
    if (e.success && !configuredMonitoring) {
        if (OS_IOS) {
            Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_BEST;
            Ti.Geolocation.distanceFilter = 5;
            Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_GPS;
            Ti.Geolocation.pauseLocationUpdateAutomatically = true;
            Ti.Geolocation.activityType = Ti.Geolocation.ACTIVITYTYPE_OTHER_NAVIGATION;
        }

        if (OS_ANDROID) {
            Ti.Geolocation.Android.addLocationProvider(Ti.Geolocation.Android.createLocationProvider({
                name: Ti.Geolocation.PROVIDER_GPS,
                minUpdateDistance: 10,
                minUpdateTime: 1
            }));
            Ti.Geolocation.Android.addLocationRule(Ti.Geolocation.Android.createLocationRule({
                provider: Ti.Geolocation.PROVIDER_GPS,
                accuracy: 10,
                maxAge: 5000,
                minAge: 1000
            }));
            Ti.Geolocation.Android.addLocationProvider(Ti.Geolocation.Android.createLocationProvider({
                name: Ti.Geolocation.PROVIDER_NETWORK,
                minUpdateDistance: 10,
                minUpdateTime: 1
            }));
            Ti.Geolocation.Android.addLocationRule(Ti.Geolocation.Android.createLocationRule({
                provider: Ti.Geolocation.PROVIDER_NETWORK,
                accuracy: 10,
                maxAge: 5000,
                minAge: 1000
            }));
            Ti.Geolocation.Android.manualMode = true;
        }
}

然后我为 iOS 暂停的位置更新添加事件监听器

if (Ti.Geolocation.locationServicesEnabled){
  Ti.Geolocation.addEventListener('location', onLocation);
  if (OS_IOS) {
    Ti.Geolocation.addEventListener('locationupdatepaused', onLocationupdate);
    Ti.Geolocation.addEventListener('locationupdateresumed', onLocationupdate);
  }
}

我的 onLocation 函数运行 函数 onLocation(e) {

    if (!e.error) {
        var coords = e.coords;
        console.log(JSON.stringify(e));
    } else {
        console.log('Error!':+JSON.stringify(e))
    }
}

在我看到的 return 数据中

{
    "success":true,
    "coords:{
        "timestamp":1488757841662,
        "speed":-1,
        "longitude":173.2793426513672,
        "floor":{"level":0},
        "latitude":-41.274879455566406,
        "accuracy":65,
        "heading":-1,
        "altitude":3.9126133918762207,
        "altitudeAccuracy":10
    },
    "code":0,
    "bubbles":true,
    "type":"location",
    "source":{
        "preferredProvider":null
    },
    "cancelBubble":false
}

我的速度或航向除了 -1 外什么都看不到,根据文档:"On iOS, a negative value indicates that the heading data is not valid."

我做错了什么?

我们遇到了同样的问题,并且正在努力解决这个问题。尝试将 Ti.Geolocation.ACCURACY_BEST 更改为 Ti.Geolocation.ACCURACY_BEST_FOR_NAVIGATION。这为我们解决了问题。