'; }else{ document.getElementById('gps_elevation').innerHTML = 'couldn\'t find the elevation'; } } }; xhttp.open("POST", "./common/get-elevation.php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); var formData = "lat="+lat+"&lng="+lng; xhttp.send(formData); var accuracyLevel = 'high'; accuracy = parseInt(accuracy/1000*100)/100; if(accuracy > 1000){ if(accuracy < 2500){ accuracyLevel = 'medium'; }else{ accuracyLevel = 'low'; } accuracy = accuracy+' km'; }else{ accuracy = accuracy+' m'; } document.getElementById("accuracy").innerHTML = accuracyLevel+' ('+accuracy+')'; document.getElementById('share_loc').value="https://whatmylocation.com/share"+"?l"+"at"+"itude="+lat+"&longitude="+lng; } function showError(error){ switch(error.code) { case error.PERMISSION_DENIED: document.getElementById('device_elevation').innerHTML = 'Location permission denied'; document.getElementById('gps_elevation').innerHTML = 'Location permission denied'; break; case error.POSITION_UNAVAILABLE: document.getElementById('device_elevation').innerHTML = 'Location information not available'; document.getElementById('gps_elevation').innerHTML = 'Location information not available'; break; case error.TIMEOUT: navigator.geolocation.getCurrentPosition(showPosition, lowAccuracyShowError, {maximumAge: 600000, enableHighAccuracy: false,timeout : 50000}); break; case error.UNKNOWN_ERROR: document.getElementById('device_elevation').innerHTML = 'Error! Please try again'; document.getElementById('gps_elevation').innerHTML = 'Error! Please try again'; break; } } function lowAccuracyShowError(error){ switch(error.code) { case error.PERMISSION_DENIED: resObj.innerHTML="User denied the request for Geolocation."; break; case error.POSITION_UNAVAILABLE: resObj.innerHTML="Location information is unavailable."; break; case error.TIMEOUT: resObj.innerHTML="The request for user location is timed out."; break; case error.UNKNOWN_ERROR: resObj.innerHTML="An unknown error occurred."; break; } } var cpyEle = document.getElementById('copy_loc'); cpyEle.addEventListener('click', copyVal); function copyVal(e){ e.preventDefault(); var tarEle = document.getElementById('share_loc'); tarEle.select(); tarEle.setSelectionRange(0, 99999); navigator.clipboard.writeText(tarEle.value); this.innerHTML = 'copied'; setTimeout(function(){ cpyEle.innerHTML = 'copy';}, 3000); }