Get the current position from the browser
async ngOnInit() { | |
const messages = this.messageBroker.getMessage(); | |
messages.pipe(filter(message => message instanceof AddNewLocationMessage)) | |
.subscribe((message: AddNewLocationMessage) => { | |
if (message) { | |
this.createDefaultLocation(); | |
this.editMode = LocationEditMode.AddNew; | |
this.isVisible = true; | |
this.setCurrentPosition(); | |
} | |
}); | |
} | |
private async setCurrentPosition() { | |
navigator.geolocation.getCurrentPosition(position => { | |
this.location = { | |
Id: this.location.Id, | |
Name: this.location.Name, | |
Description: this.location.Description, | |
Latitude: position.coords.latitude, | |
Longitude: position.coords.longitude | |
}; | |
}, error => { | |
this.logging.logError(error.message); | |
this.messageBroker.sendMessage(new ErrorOccurredMessage(error.message)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment