Below is a sample code snippet demonstrating the procedure on how to get the current user location Windows 8.1 Store App using JavaScript.
How to Get the Current Location from Window 8.1 Store App using JavaScript ?
Add the button and the span element to the html page where you want to show the current location.
<button id="GetLocation"> Get Location </button> <span id="locationinformation"></span>
Add the methods to get the current location in the javascript file . To retreive the location , we should use the Geolocator class that is defined in the Windows.Devices.Geolocation namespace and then use the getGeopositionAsync method .>
Bind an event handler once the location is received so that the data can be retreived from the position and displayed in the span id that is defined in the screen .
function GetLocationFunction() { var location = new Windows.Devices.Geolocation.Geolocator(); location.getGeopositionAsync().then(UpdateLocation, null); } function UpdateLocation(position) { document.getElementById('locationinformation').innerHTML = position.coordinate.point.position.latitude + "," + position.coordinate.point.position.longitude; }
Leave a Reply