title: Angular 2 - Wait for Promise before continuing
body: <p>I'm need to create a geolocation variable and send the values to an API but I'm trouble.</p>
  
  <pre><code>public virtualRegistrationHandler(e: any): void {
      e.preventDefault();
      console.log("loop");
      if (navigator.geolocation) {
          let geoLoc = navigator.geolocation.getCurrentPosition(this.setGeoLoc);
  
          this.VirtualRegistrationService.virtualRegistration(geoLoc)
              .subscribe(
              response =&gt; this.toastyCommunicationService.addSuccesResponseToast(response),
              error =&gt; this.toastyCommunicationService.addErrorResponseToast(error)
              );
      } else {
          this.toastyCommunicationService.addErrorResponseToast("Geolocation is not supported by this browser.");
      }
  }
  
  private setGeoLoc(position: any) {
      console.log("Latitude " + position.coords.latitude, "Longitude " + position.coords.longitude);
      let geoLoc = { "Latitude": position.coords.latitude, "Longitude": position.coords.longitude };
      return geoLoc;
  }
  </code></pre>
  
  <p>this is my current code, but it doesn't wait for <code>geoLoc</code> to be returned, so right now it sends an undefined parameter to the API.</p>
  
  <p>I want to API call to wait untill <code>geoloc</code> is set. </p>
  
  <p>I did some googling and I came accros promises, however I'm having trouble writing the syntax and I cant find any working example.</p>
  
  <p>How do I correctly write my code so that geoLoc has to be set first before my function continues to the API?</p>