Skip to content

Instantly share code, notes, and snippets.

@abjerner
Created September 27, 2014 23:08
Show Gist options
  • Save abjerner/db1529f784a60dd1026e to your computer and use it in GitHub Desktop.
Save abjerner/db1529f784a60dd1026e to your computer and use it in GitHub Desktop.
Example controller for a AngularJS property editor in Umbraco 6
angular.module('umbraco').controller('GoogleAddressSearchController', ['$scope', '$http', function ($scope, $http) {
if (!$scope.model.address) $scope.model.address = '';
$scope.address = $scope.model.address;
$scope.suggestions = [];
$scope.addressKeyDown = function () {
$http({
url: 'http://maps.googleapis.com/maps/api/geocode/json',
params: {
address: $scope.address
}
}).success(function (res) {
$scope.suggestions = res.results;
}).error(function () {
alert('Something bad happened!!!');
});
};
$scope.select = function (r) {
$scope.model.address = r.formatted_address;
$scope.model.latitude = r.geometry.location.lat;
$scope.model.longitude = r.geometry.location.lng;
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment