Create a gist now

Instantly share code, notes, and snippets.

@justinyoo /hello.ts Secret
Created Mar 16, 2017

What would you like to do?
Getting Geolocation on Mobile Devices using Vue.js + TypeScript + ASP.NET Core
...
export default class Hello extends Vue {
...
latitude?: number = null;
longitude?: number = null;
altitude?: number = null;
...
public getLocation (): void {
var geo: Geolocation = navigator.geolocation;
if (geo == null) {
console.log("No geolocation support");
return;
}
var options: PositionOptions = new GpsPositionOptions(true, 30000, 30000);
geo.getCurrentPosition((p: Position) => this.success(p), (ex: PositionError) => this.error(ex), options);
}
private success (position: Position): PositionCallback {
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
this.altitude = position.coords.altitude;
return null;
}
private error(ex: PositionError): PositionErrorCallback {
console.log(ex.message);
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment