簡體   English   中英

Titanium 地理位置 distanceFilter 屬性未按預期工作

[英]Titanium geolocation distanceFilter property is not working as expected

在此處需要地理定位幫助 API - 即使在使用 Titanium.Geolocation.distanceFilter = 10; 10 米回調 function 被隨機觸發而不會到處移動。 知道這里有什么問題嗎?

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;

實際情況是,每當我單擊獲取位置時,它都會給我當前位置。 然后我嘗試將它拖到 map 或圖像視圖以獲取最近的位置。 突然我查看 go 當前位置。 這是因為回調而發生的? 如何擺脫這個?

與您的代碼無關,只是 GPS 不准確。

GPS 精度(幾乎)永遠不會超過 10 米,這意味着它可以相差 10 米。 當它重新計算您的 position 時,它可能會下降 10 米,因此即使您仍然完美地保持 GPS 精度,您仍然可能有大約 10 米的差異。

也就是說,當您坐在建築物中的計算機后面時,您可能沒有最佳的 GPS 精度,您的精度可能接近 30-45 米。 這意味着每次重新計算都可以很容易地相差 10 米。

您的解決方案實際上是使用此屬性的速率限制。 該屬性將確保它不會每秒觸發多次,然后您可以在自己的代碼中限制您使用它執行的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM