-
-
Save justinyoo/03c2e1b4e882ea81d1f5dca275410005 to your computer and use it in GitHub Desktop.
Getting Geolocation on Mobile Devices using Vue.js + TypeScript + ASP.NET Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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