title: Reverse geocoding using Angular 2
body: <p>I am using reverse geocoding using Angular 2, it is working fine but i am not able to set the values(i.e, city name) using service(setter and getter)</p>
  
  <pre class="lang-js prettyprint-override"><code>import { ShareService } from './services/ShareService';
  class ConferenceApp {
     constructor(public shareService: ShareService){
       this.getGeoLocation();
  
     }
      public getGeoLocation(){
            if (navigator.geolocation) {
                var options = {
                  enableHighAccuracy: true
                };
  
                navigator.geolocation.getCurrentPosition(position=&gt; {
                  this.lat = position.coords.latitude;
                  this.long = position.coords.longitude;
                  let geocoder = new google.maps.Geocoder();
                  let latlng = new google.maps.LatLng(this.lat, this.long);
                  let request = {
                    latLng: latlng
                  };   
  
                    geocoder.geocode(request, function(results, status) {
                      if (status == google.maps.GeocoderStatus.OK) {
                        if (results[0] != null) {
                         let city = results[0].address_components[results[0].address_components.length-4].short_name;                      
  
                         this.shareService.setLocationDetails(city);
  
  
                        } else {
                          alert("No address available");
                        }
                      }
                    });
  
                }, error =&gt; {
                  console.log(error);
                }, options);
            }
          }
  }
  </code></pre>
  
  <p>if i try to set using service, 
  <strong>this.shareService.setLocationDetails(city);</strong>
  I am getting error saying, </p>
  
  <pre><code>app.ts:303 Uncaught TypeError: Cannot read property 'shareService' of undefined
  </code></pre>
  
  <p>The service:</p>
  
  <pre class="lang-js prettyprint-override"><code>locationObj: any;
  setLocationDetails(locationObj){
        this.locationObj = locationObj;
      }
      getLocationDetails(){
        return this.locationObj;
      }
  </code></pre>