更新。根据我的理解,并不是真正重复的连接,在这种情况下不起作用。
我已经尝试过下面Baszz所提供的以下内容,但似乎打破了角度。测试表达式我在视图中显示纬度,经度和邮政编码,当我使用它时显示表达式代码:
$http.get('//api.postcodes.io/postcodes?limit=1&lon=' +
$geolocation.position.coords.longitude +
'&lat=' +
$geolocation.position.coords.latitude);
我使用Angular的ngGeolocation模块查找用户的纬度和经度,以便使用postcodes.io来计算邮政编码。
纬度位于:$geolocation.position.coords.latitude
经度位于:$geolocation.position.coords.longitude
以下示例给出了邮政编码结果:
$http.get('//api.postcodes.io/postcodes?limit=1&lon=-0.1276250&lat=51.5033630')
我想将经度和纬度插入上面的代码行。 怎么办呢?
完整的代码:
var myApp = angular.module('myApp', ['ngGeolocation']);
myApp.controller('geolocCtrl', ['$scope', '$geolocation', '$http',
function($scope, $geolocation, $http) {
$scope.$geolocation = $geolocation
// basic usage
$geolocation.getCurrentPosition().then(function(location) {
$scope.location = location
});
// regular updates
$geolocation.watchPosition({
timeout: 60000,
maximumAge: 2,
enableHighAccuracy: true
});
$scope.testing = "300";
$scope.coords = $geolocation.position.coords; // this is regularly updated
$scope.error = $geolocation.position.error; // this becomes truthy, and has 'code' and 'message' if an error occurs
$http.get('//api.postcodes.io/postcodes?limit=1&lon=-0.1276250&lat=51.5033630')
.success(function (data) {
$scope.postcode = data.result[0].postcode;
var postcode2 = $scope.postcode
})
.error(function (data, status) {
console.log(data);
});
}]);
答案 0 :(得分:0)
根据您提供的信息,我会说:
$http.get('//api.postcodes.io/postcodes?limit=1&lon=' +
$geolocation.position.coords.longitude +
'&lat=' +
$geolocation.position.coords.latitude);
答案 1 :(得分:0)
这是模块的问题。