【问题标题】:Titanium geolocation distanceFilter property is not working as expectedTitanium 地理位置 distanceFilter 属性未按预期工作
【发布时间】:2023-04-03 05:31:01
【问题描述】:

在此处需要地理定位 API 的帮助 - 即使在使用 Titanium.Geolocation.distanceFilter = 10; 10 米回调函数被随机触发,而无需到处移动。知道这里有什么问题吗?

function Geolocate() {
    var self = this;

    // The callback function we should call when location is finally determined
    this.locationReceivedCallback = function () {};
    // Check if location event is already triggered or not 
    this.isLocationEventRegister = false;
    // The function that unregisters the location event
    this.unregisterLocationEvent = function () {
        this.isLocationEventRegister = false;
        Ti.Geolocation.removeEventListener('location', self.locationReceivedCallback);
    };
}

Geolocate.prototype.init = function () {
    // Setting up some preference values

    Titanium.Geolocation.distanceFilter = 10; //The minimum change of position (in meters) before a 'location' event is fired.

    if (deviceDetect.isIos()) {
        Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_BEST; // Using this value on Android enables legacy mode operation, which is not recommended.

    } else {
        Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_LOW; //Using this value on Android enables simple mode operation.
    }
};

Geolocate.prototype.getCurrentPosition = function (callback) {
    this.isLocationEventRegister = true;
    this.locationReceivedCallback = callback;
    Titanium.Geolocation.addEventListener("location", this.locationReceivedCallback);
};

Geolocate.prototype.locationServicesAreAvailable = function () {
    if (Titanium.Geolocation.locationServicesEnabled) {
        return true;
    } else {
        return false;
    }
};

Geolocate.prototype.cancelLocationRequest = function () {
    this.unregisterLocationEvent();
};

module.exports = Geolocate;

实际情况是,每当我点击获取位置时,它都会给我当前位置。然后我试图将它拖到最近的地方的地图或图像视图。突然我的视野转到当前位置。这是因为回调而发生的?如何摆脱这个?

【问题讨论】:

    标签: titanium titanium-mobile appcelerator-titanium


    【解决方案1】:

    这与您的代码无关,只是 GPS 不准确。

    GPS 精度(几乎)永远不会超过 10 米,这意味着它可以在 10 米之外。当它重新计算您的位置时,它可能会沿着直线向下 10 米,因此即使您的 GPS 准确度完全没有问题,您仍然可能会有大约 10 米的差异。

    也就是说,当您坐在建筑物中的计算机后面时,您可能没有最佳的 GPS 精度,您的精度可能接近 30-45 米。这意味着每次重新计算都可以很容易地相差 10 米。

    您的解决方案实际上是在使用此属性之上的速率限制。该属性将确保它不会每秒触发多次,然后您可以在自己的代码中限制您使用它执行的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-26
      • 2021-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 2011-08-28
      • 1970-01-01
      相关资源
      最近更新 更多