2017-05-16 6 views
1

私はanugularJSの初心者ですので、おそらく私は何か間違っています。私の角度バージョンは1.6.4です。ジオロケーションの場合、私はこのモジュールangularjs-geolocationを使用しています。ここにジオロケーションモジュールplunkerのデモがあります。私のプロジェクトにこのモジュールを組み込み、ブラウザでテストするとこのエラーが出ます。私はすべてのステップを踏んだが、私は何かが足りない。AngularJS:あなたの所在地を特定できません

おそらく未処理の拒絶:あなたの場所

を決定することができません。これは私のユーザーsettings.component.jsファイルです:これは私のユーザーsettings.template.htmlある

(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] 
    }); 

}()); 

ファイル:

<div class="text-center"> 
    <button type="button" class="btn btn-default" ng-click="model.location()">Location</button> 
    {{model.coords}} 
</div> 

マイApp.jsファイル:

angular.module(__appName, ["geolocation"]); 

答えて

0

私は私のローカルマシンに次のコードを実行した:

<html>  
    <head> 
    <script data-require="[email protected]" 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> 

そしてそれは働きました。それはあなたのものと似たものではありません。 のPlunkerに表示されていない場所は、のPlunkerになる可能性があります。

ローカルサーバーで試してみてください。それが動作します。

関連する問題