Answers for "angular get geolocation"

1

angular get geolocation

locationService.ts 
getPosition(): Promise<any>
  {
    return new Promise((resolve, reject) => {

      navigator.geolocation.getCurrentPosition(resp => {

          resolve({lng: resp.coords.longitude, lat: resp.coords.latitude});
        },
        err => {
          reject(err);
        });
    });

  }
component.ts
this.locationService.getPosition().then(pos=>
  {
     console.log(`Positon: ${pos.lng} ${pos.lat}`);
});
Posted by: Guest on March-30-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language