-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathangular-reverse-geocode.js
More file actions
30 lines (30 loc) · 1.11 KB
/
angular-reverse-geocode.js
File metadata and controls
30 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* AngularJS reverse geocoding directive
* @author Jason Watmore <jason@pointblankdevelopment.com.au> (http://jasonwatmore.com)
* @version 1.0.0
*/
(function () {
angular.module('angularReverseGeocode', [])
.directive('reverseGeocode', function () {
return {
restrict: 'E',
template: '<div></div>',
link: function (scope, element, attrs) {
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(attrs.lat, attrs.lng);
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
element.text(results[1].formatted_address);
} else {
element.text('Location not found');
}
} else {
element.text('Geocoder failed due to: ' + status);
}
});
},
replace: true
}
});
})();