diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..1c2d52b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.idea/*
diff --git a/README.md b/README.md
index 5280b54..610c518 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,13 @@
angular-reverse-geocode
=======================
-AngularJS reverse geocoding directive
-
+AngularJS reverse geocoding directive using AngularJS 1.5 component() syntax.
###Demo
To see a demo and further details go to http://jasonwatmore.com/post/2014/02/15/AngularJS-Reverse-Geocoding-Directive.aspx
###Installation
-
Install using bower: `bower install angular-reverse-geocode`
Alternatively download the code and include the angular-reverse-geocode.js file in your page.
@@ -24,6 +22,16 @@ angular.module('myApp', ['angularReverseGeocode']);
To use add a reverse-geocode tag to your page with attributes containing lat and long coordinates, e.g:
+####Optional attributes
+
+`geocode-results-index` - Google returns many levels of results. Index 0 is generally the most explicit. Default is 0.
+https://developers.google.com/maps/documentation/javascript/geocoding#reverse-geocoding-by-location
+
+`location-not-found-text` - Customize the message displayed if no location is found. Default is "Location not found".
+
+`geocode-failure-text` - Customize the message displayed when a geocoding error happens. Default is "Geocoder failed due to: " followed by the error message.
+
+
```html
-
+
```
\ No newline at end of file
diff --git a/angular-reverse-geocode.js b/angular-reverse-geocode.js
index d8656f9..e2a4a1b 100644
--- a/angular-reverse-geocode.js
+++ b/angular-reverse-geocode.js
@@ -1,30 +1,39 @@
/**
* AngularJS reverse geocoding directive
* @author Jason Watmore (http://jasonwatmore.com)
- * @version 1.0.0
+ * @author Larry Stone
+ * @version 2.0.0
*/
(function () {
- angular.module('angularReverseGeocode', [])
- .directive('reverseGeocode', function () {
- return {
- restrict: 'E',
- template: '',
- 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
- }
+ angular.module('angularReverseGeocode', []).component('reverseGeocode', {
+ bindings: {
+ lat: '@',
+ lng: '@',
+ geocodeResultsIndex: '@?',
+ locationNotFoundText: '@?',
+ geocodeFailureText: '@?'
+ },
+ controller: function ($scope) {
+ var vm = this;
+ var defaultResultsIndex = 0;
+ var defaultLocationNotFoundText = 'Location not found';
+ var defaultGeocodeFailureText = 'Geocoder failed due to: ';
+ var geocoder = new google.maps.Geocoder();
+ var latlng = new google.maps.LatLng(vm.lat, vm.lng);
+ var resultsIndex = vm.geocodeResultsIndex || defaultResultsIndex;
+
+ geocoder.geocode({ 'latLng': latlng }, function (results, status) {
+ if (status === 'OK') {
+ vm.address = results[resultsIndex].formatted_address;
+ } else if (status === 'ZERO_RESULTS') {
+ vm.address = vm.locationNotFoundText || defaultLocationNotFoundText
+ } else {
+ vm.address = vm.geocodeFailureText || (defaultGeocodeFailureText + status);
+ }
+ $scope.$apply();
+ });
+ },
+ template: '{{$ctrl.address}}
'
});
+
})();
\ No newline at end of file
diff --git a/bower.json b/bower.json
index e01709e..dd637e5 100644
--- a/bower.json
+++ b/bower.json
@@ -1,8 +1,9 @@
{
"name": "angular-reverse-geocode",
- "version": "1.0.0",
+ "version": "2.0.0",
"authors": [
- "Jason Watmore (http://jasonwatmore.com)"
+ "Jason Watmore (http://jasonwatmore.com)",
+ "Larry Stone "
],
"description": "AngularJS reverse geocoding directive",
"main": "angular-reverse-geocode.js",
@@ -21,6 +22,6 @@
"tests"
],
"dependencies": {
- "angular": "~1.2.16"
+ "angular": "~1.5.5"
}
}
diff --git a/demo/demo.html b/demo/demo.html
index 462891a..fee1b92 100644
--- a/demo/demo.html
+++ b/demo/demo.html
@@ -10,7 +10,7 @@
-
+