Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS:无法确定您的位置_Angularjs - Fatal编程技术网

AngularJS:无法确定您的位置

AngularJS:无法确定您的位置,angularjs,Angularjs,我是anugularJS的新手,所以我可能做错了什么。我的角度版本是1.6.4。对于地理定位,我使用这个模块。这是地理定位模块的演示。通过在我的项目中包含此模块并在浏览器上进行测试,我发现了此错误。我已经遵循了所有的步骤,但我遗漏了一些东西 可能未处理的拒绝:无法确定您的位置 这是我的user-settings.component.js文件: (function () { "use strict"; var module = angular.module(__appName);

我是anugularJS的新手,所以我可能做错了什么。我的角度版本是1.6.4。对于地理定位,我使用这个模块。这是地理定位模块的演示。通过在我的项目中包含此模块并在浏览器上进行测试,我发现了此错误。我已经遵循了所有的步骤,但我遗漏了一些东西

可能未处理的拒绝:无法确定您的位置

这是我的user-settings.component.js文件:

(function () {
    "use strict";

    var module = angular.module(__appName);

    function controller($http, geolocation) {
        var model = this;

        model.location = function () {
            console.log("inside");

            model.coords = geolocation.getLocation().then(function (data) {
                return { lat: data.coords.latitude, long: data.coords.longitude };
            });
       }

    }

    module.component("userSettings", {
        templateUrl: "components/user-settings/user-settings.template.html",
        bindings: {
            userId: "<"
        },
        controllerAs: "model",
        controller: ["$http", "geolocation", controller]
    });

}());

我已在本地计算机上运行以下代码:

<html>    
  <head>
    <script data-require="angular.js@1.2.0-rc2" data-semver="1.2.0-rc2" src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
    <script src="https://rawgithub.com/arunisrael/angularjs-geolocation/master/dist/angularjs-geolocation.min.js"></script>
    <script src="script.js"></script>
  </head>

  <body ng-app="myApp">
    <div ng-controller="mainCtrl">
      <p>Your location is: {{coords}}</p>
    </div>
  </body>
<script>
angular.module('myApp',['geolocation'])
  .controller('mainCtrl', function ($scope,geolocation) {
    geolocation.getLocation().then(function(data){
      $scope.coords = {lat:data.coords.latitude, long:data.coords.longitude};
    });
});
</script>
</html>

您的位置是:{{coords}

angular.module('myApp',['geolocation'])) .controller('mainCtrl',函数($scope,geolocation){ geolocation.getLocation().then(函数(数据){ $scope.coords={lat:data.coords.latitude,long:data.coords.longitude}; }); });
它成功了。这和你的没什么不同。Plunker中未显示的位置可能是Plunker问题

在本地服务器上试试。它会起作用的

angular.module(__appName, ["geolocation"]);
<html>    
  <head>
    <script data-require="angular.js@1.2.0-rc2" data-semver="1.2.0-rc2" src="http://code.angularjs.org/1.2.0-rc.2/angular.js"></script>
    <script src="https://rawgithub.com/arunisrael/angularjs-geolocation/master/dist/angularjs-geolocation.min.js"></script>
    <script src="script.js"></script>
  </head>

  <body ng-app="myApp">
    <div ng-controller="mainCtrl">
      <p>Your location is: {{coords}}</p>
    </div>
  </body>
<script>
angular.module('myApp',['geolocation'])
  .controller('mainCtrl', function ($scope,geolocation) {
    geolocation.getLocation().then(function(data){
      $scope.coords = {lat:data.coords.latitude, long:data.coords.longitude};
    });
});
</script>
</html>