title: creating an angular service with Google map API service call back function
body: <p>I am trying to create an angular service which uses google map geocoder, however I found the callback from google was executed after the execution of service function.</p>
  
  <h1>controller</h1>
  
  <pre><code>app.controller( 'AppCtrl',['geocoder',function AppCtrl (geocoder) {
     var result=geocoder.geocode('greek');
     console.log(result);
  });
  </code></pre>
  
  <h1>service</h1>
  
  <pre><code>app.service('geocoder',function() {
              this.geocode=function(address) {
                      var geocoder = new google.maps.Geocoder();
                      geocoder.geocode( { 'address': address}, function(results, status) {
                              if (status == google.maps.GeocoderStatus.OK) {
                                      console.log(results);
                                      return results;
                              } else {
                                      return ('Geocode was not successful for the following reason: ' + status);
                              }
                      });
              };
      });
  </code></pre>
  
  <p>The problem is , the console.log(result) in the controller outputs undefined and the console.log(results) in the service get the results back from google after the call of the function. That is, the callback function didn't return the results in time.</p>
  
  <p>Is there a way to overcome this problem?
  Thanks.</p>