Update. Not really a duplicate as concatenation, as I understand it, is not working in this case.
I've tried the following as kindly provided by Baszz below but it seems to break angular. Test expressions I have showing latitude, longitude and the postcode in the view show the expression code instead when I use this:
$http.get('//api.postcodes.io/postcodes?limit=1&lon=' +
$geolocation.position.coords.longitude +
'&lat=' +
$geolocation.position.coords.latitude);
I'm using the ngGeolocation module for Angular to find the latitude and longitude of the user in order to work out the postcode using postcodes.io.
Latitude is at: $geolocation.position.coords.latitude
Longitude is at: $geolocation.position.coords.longitude
The following example gives a postcode result:
$http.get('//api.postcodes.io/postcodes?limit=1&lon=-0.1276250&lat=51.5033630')
I want to insert the longitude and latitude into the above line of code. How can this be done?
The complete code:
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);
});
}]);