-
Notifications
You must be signed in to change notification settings - Fork 3
/
getloc.js
26 lines (23 loc) · 891 Bytes
/
getloc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function getLocation() {
var x = document.getElementById("demo");
if (navigator.geolocation) {
navigator.geolocation.watchPosition(showPosition);
}
else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var lat = position.coords.latitude.toFixed(2);
var lon = position.coords.longitude.toFixed(2);
document.getElementById("demo").innerHTML = "You're around Latitude: " + lat + " and Longitude: " + lon;
var xhr = new XMLHttpRequest();
var params = "latitude=" + lat + "&longitude=" + lon;
console.log("Params: " + params);
xhr.open('PUT', '/locations', true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function () {
console.log("Response:" & this.responseText);
};
xhr.send(params);
}