I am working with typescript and trying to get the geolocation of where we currently are. I can get the location, but my code continues without setting the location. I decided to use await and promise. I created a service that looks like:
@Injectable()
export class GoogleMapsService {
private latitude: number;
private longitude:number;
public currentLongitude(): number {
return this.longitude;
}
public currentLatitude(): number {
return this.latitude;
}
constructor() {
this.setCurrentLocation();
}
private async setCurrentLocation() {
let location: GoogleLocation = await this.getLocation();
this.latitude = location.latitude;
this.longitude = location.longitude;
}
private getLocation(): Promise<GoogleLocation> {
let promise = new Promise<GoogleLocation>(() => {
let location = new GoogleLocation();
navigator.geolocation.getCurrentPosition(position => {
location.latitude = position.coords.latitude;
location.longitude = position.coords.longitude;
});
return location;
});
return promise;
}
}
so my question is how can I set this while i await it. so when i try to access it it is there?