I'm using HTML Geolocation API to get the location of the user in web application after some interval. When the web application is in the foreground it is working fine on mobile browsers even in safari on iPhone and also in google chrome on android. But when the web application in the browser goes in the background or when mobile goes into the sleep mode then I am unable to get the location using HTML Geolocation API. Below is the sample code
<script>
setInterval(function(){
getLocation();
}, 10000);
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
// save the position
}
</script>
Any help?