私はこの問題を解決するために成功しなかった。 getCurrentPosition()は約束を返し、.then()関数内の$ scope.map.centerを呼び出すと動作することを理解しています。また、$ scopeはダイジェストサイクルで実行され、プロミスが解決されたときにそのプロパティとオブジェクトが更新されることも理解しています。私はこのすべてに新しいです、そして、私は理にかなっていることを願っています。
しかし、console.log($ scope.map)が期待通りに動作し、{map.center}}が期待どおりに表示されるがconsole.log(map.center)が表示されるため、 .then()関数の外に空のオブジェクトを返します。
ご協力いただきありがとうございます。
$scope.map = {
control: {},
center: {},
zoom: 16
};
$geolocation.getCurrentPosition({
timeout: 60000,
maximumAge: 250,
enableHighAccuracy: true
}).then(function(position) {
$scope.map.center.latitude = position.coords.latitude;
$scope.map.center.longitude = position.coords.longitude;
});
//Output
console.log($scope.map); //returns full object including data within $scope.map.center
console.log($scope.map.center); //returns an empty object. I am looking to convert this to an array using lodash.
{{ map.center }} works fine and returns the coordinates of my current location
**編集(コンソールのアップロードされた画像)**
This is what I see in the console. First object is $scope.map Second object is $scope.map.center
詳細な回答ありがとうございます!あなたの説明でそれを見逃したら私を許してください。しかし、私はなぜ$ scope.mapが最初に働いたのか疑問に思っています。 – nubianrover
それは本当にしなかったか、コントローラの機能の上に作成したオブジェクトを取得していたか、呼び出しが部分的に終了した可能性があります。 –
もう少しチェックをした後、私は今、HTML5 GeolocationがCoordinatesという特別なオブジェクトタイプを返すという事実と関係があると考えています。それは今私の好奇心を満足させるでしょう。しかし、その後、私は間違っているかもしれません。 – nubianrover