我正在使用 Geolocation HTML5 API。我正在使用 angular.js。我写了一个小工厂函数
myApp.factory("GeolocationService", ['$q', '$window', '$rootScope',
function($q, $window, $rootScope) {
return function() {
var deferred = $q.defer();
if (!$window.navigator) {
$rootScope.$apply(function() {
deferred.reject(new Error("Geolocation is not supported"));
});
} else {
$window.navigator.geolocation.getCurrentPosition(function(position) {
$rootScope.$apply(function() {
deferred.resolve(position);
});
}, function(error) {
$rootScope.$apply(function() {
deferred.reject(error);
});
});
}
return deferred.promise;
}
}
]);
当我使用它时。它给我一个错误
PositionError {消息:“网络位置提供商位于‘https://www.googleapis.com/’:返回错误代码 404。”,代码:2,PERMISSION_DENIED:1,POSITION_UNAVAILABLE:2,TIMEOUT:3}
谁能帮忙解决一下??
最佳答案
您必须启用 wifi 连接才能使用 navigator.geolocation
(即使您没有使用它!)
更多解释in this answer .
关于javascript - PositionError 网络位置提供程序位于 'https://www.googleapis.com/' : Returned error code 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25729107/