Skip to content

Instantly share code, notes, and snippets.

@LarsBergqvist
Last active February 1, 2020 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LarsBergqvist/2be054607a7d18ce5e15061670b4a6f7 to your computer and use it in GitHub Desktop.
Save LarsBergqvist/2be054607a7d18ce5e15061670b4a6f7 to your computer and use it in GitHub Desktop.
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