Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html ng-app="myApp">
  <head>
    <script src="//maps.googleapis.com/maps/api/js?v=3.exp"></script>
  </head>
  <body ng-controller="MyCtrl as my">
    <div class="container">
      <h3> Using the Directive </h3>
    <div class="row">
      <div class="col-md-4">
        <h4>
          Reverse Geocode from fixed lat and lng:
           <reverse-geocode lat="-12.928615" lng="-38.509741"></reverse-geocode>
        </h4>
      </div>
      <div class="col-md-4">
        <h4>
          Reverse Geocode scope variables from controller:
           <reverse-geocode lat="{{my.lat}}" lng="{{my.lng}}"></reverse-geocode>
        </h4>
      </div>
      <div class="col-md-4">
        <h4>
          <a href="https://github.com/guiassemany/angular-reverse-geocode">Github repo</a>
        </h4>
      </div>
    </div>
    <div class="row">
      <h3> Using the service </h3>
      <div class="col-md-12">
        <h4> Full address from controller </h4>
        {{my.formatted_address}}
      </div>
    </div>
    </div>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                angular.module('myApp', ['AngularReverseGeocode']);

angular.module('myApp')
        .controller('MyCtrl', MyCtrl);

MyCtrl.$inject = ['$scope', 'reverseGeocode'];

function MyCtrl($scope, reverseGeocode){
  var vm = this;
          vm.lat = "-12.914090";
          vm.lng = "-38.493835";

          vm.formatted_address = "";

          activate();

          function activate(){
            reverseGeocode.geocodePosition(vm.lat, vm.lng, function(address){
               vm.formatted_address = address;
               $scope.$apply();
            });
          }
}

/**
 * AngularJS reverse geocoding directive
 * @author Guilherme Assemany <guilhermeassemany@hotmail.com> (http://assemany.com)
 * @version 1.0.0
 */
(function () {
    angular.module('AngularReverseGeocode', [])
    .service('reverseGeocode', ['$http', function($http){

      var vm = this;

      vm.geocodePosition = geocodePosition;

      var geocoder = new google.maps.Geocoder();

      function geocodePosition(lat, lng, fn) {
        var latlng = new google.maps.LatLng(lat, lng);
        geocoder.geocode({
          latLng: latlng
        }, function(responses) {
          if (responses && responses.length > 0) {
             fn(responses[0].formatted_address);
          } else {
             alert('Error while trying to find the location');
          }
        });
      }
    }])
    .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[0]) {
                            element.text(results[0].formatted_address);
                        } else {
                            element.text('Location not found');
                        }
                    } else {
                        element.text('Geocoder failed due to: ' + status);
                    }
                });
            },
            replace: true
        };
    });
})();

              
            
!
999px

Console