Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Created March 16, 2017 05:02
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 justinyoo/03c2e1b4e882ea81d1f5dca275410005 to your computer and use it in GitHub Desktop.
Save justinyoo/03c2e1b4e882ea81d1f5dca275410005 to your computer and use it in GitHub Desktop.
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