navigator.geolocation.getCurrentPosition iPhone5 没有超时

navigator.geolocation.getCurrentPosition not timing out for iPhone5

我在定位服务中有以下代码:

.factory('Location', function($q, $ionicLoading) {
        return {
            getCurrentPosition: function() {
                var deferred  = $q.defer();
                $ionicLoading.show({template: 'Getting Location...'});
                navigator.geolocation
                    .getCurrentPosition(
                    function (data) {
                        $ionicLoading.hide();
                        deferred.resolve(data);
                    },
                    function (error) {
                        var data = 'Error getting current position.';
                        $ionicLoading.hide();
                        deferred.reject(data);
                    },
                    {timeout:5000, enableHighAccuracy:false});
                return deferred.promise;
            }
        }
    }

我使用 PhoneGap Build 构建项目,然后安装在我的 iPhone5 上。

在我关闭定位服务之前一切正常:

我希望在 5 秒后发生超时并显示错误。但是,我的应用程序只是挂起。没有触发任何想法超时?

这是一个语法问题。

我上面的简化代码没有包含这个错误的语法:

var data = {};
switch(error.code) {
//...error message code here
}
data.push({errorCode: error.code,
           errorMessage: errorMessage});

我通过更改为以下内容来修复:

switch(error.code) {
//...error message code here
}
var data = {errorCode: error.code,
                errorMessage: errorMessage};