Subroutines

Use the following javascript snippet to access the Users location.

var x = document.getElementById("pos"); function getLocation() {
if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation not enabled.";
} }

function processPosition(position) {
x.innerHTML = "Lat: " +
position.coords.latitude + "<br>Long: " +
position.coords.longitude;
}

By navigator.geolocation the user will be asked for permission to share the location. navigator.geolocation.getCurrentPosition(showPosition) retrieves the location and passes it to the callback function showposition. In the position.coords object lat and long can be accessed, displayed or sent to a server via REST.

OperatingSystem:

ProgrammingLanguage:

Subscribe to Subroutines