navigator.geolocation.getCurrentPosition在Windows Phone 8.1中不起作用

时间:2015-08-17 12:02:03

标签: javascript windows cordova windows-phone-8.1 phonegap-plugins

我正在尝试使用Cordova / PhoneGap获取当前的经度和纬度。但我在失败功能上遇到此错误:

  

位置检索超时。

我已将maximumAge设置为5000并超时为10000。

这是我正在使用的Cordova代码段:

getCurrentPosition:function(successCallback, errorCallback, options) {

    argscheck.checkArgs('fFO', 'geolocation.getCurrentPosition', arguments);
    options = parseParameters(options);

    var timeoutTimer = {timer:null};

    var win = function(p) {
        clearTimeout(timeoutTimer.timer);
        if (!(timeoutTimer.timer)) {

            return;
        }
        var pos = new Position(
            {
                latitude:p.latitude,
                longitude:p.longitude,
                altitude:p.altitude,
                accuracy:p.accuracy,
                heading:p.heading,
                velocity:p.velocity,
                altitudeAccuracy:p.altitudeAccuracy
            },
            (p.timestamp === undefined ? new Date() : ((p.timestamp instanceof Date) ? p.timestamp : new Date(p.timestamp)))
        );
        geolocation.lastPosition = pos;
        successCallback(pos);
    };
    var fail = function(e) {
        clearTimeout(timeoutTimer.timer);
        timeoutTimer.timer = null;
        var err = new PositionError(e.code, e.message);
        if (errorCallback) {
            errorCallback(err);
        }
    };

    if (geolocation.lastPosition && options.maximumAge && (((new Date()).getTime() - geolocation.lastPosition.timestamp.getTime()) <= options.maximumAge)) {
        successCallback(geolocation.lastPosition);
      } else if (options.timeout === 0) {
        fail({
            code:PositionError.TIMEOUT,
            message:"timeout value in PositionOptions set to 0 and no cached Position object available, or cached Position object's age exceeds provided PositionOptions' maximumAge parameter."
        });

    } else {
        if (options.timeout !== Infinity) {
            timeoutTimer.timer = createTimeout(fail, options.timeout);
        } else {
            timeoutTimer.timer = true;
        }
        exec(win, fail, "Geolocation", "getLocation", [options.enableHighAccuracy, options.maximumAge]);
    }
    return timeoutTimer;
},

一切似乎都没问题。但它不会调用 successCallback 函数。我不知道我做错了什么。

1 个答案:

答案 0 :(得分:1)

我不知道你是否已经解决了这个问题,而且我没有看到你发送给 array:2 [ 0 => array:15 [ "id" => 1 "user_id" => 24 "title" => "Langkawi" "description" => "Lorem ipsum WTF???" "category" => 1 "city" => 2 "image_url" => "https://qwert.s3-us-west-2.amazonaws.com/default/no-image.png" "price" => "30" "location" => "Langkawi" "discount" => "10%" "start_date" => "0000-00-00" "end_date" => "0000-00-00" ] 1 => array:15 [ "id" => 6 "user_id" => 24 "title" => "ADVANCE AND DEFENSIVE DRIVING COURSE # SHAH ALAM" "description" => "Lorem ipsum WTF??? V2" "category" => 0 "city" => 0 "image_url" => "https://qwert.s3-us-west-2.amazonaws.com/default/no-image.png" "price" => "" "location" => "" "discount" => "" "start_date" => "0000-00-00" "end_date" => "0000-00-00" ] ] 方法的选项,但是我使用这些选项让它在wp8.1上工作:

getCurrentPosition