语言

Menu
Sites
Language
Is it possible to check the current location when the app is running in the background?

As the title suggests, I'd like to be able to get user's location while the app is running in the background, is it even possible for the web app?

响应

2 回复
konduri sai swathi

Hi,

Try the below code

function onPositionUpdate(position)
{
    console.log("inside ------")
	var lat = position.coords.latitude;
	var lng = position.coords.longitude;
	console.log("Current position: " + lat + " " + lng);
	var position='<p>latitude='+lat+'</p>'
	+'<p>longitude='+lng+'</p>';

}

function errorHandler(err) {
	console.log("inside error handler");
	if(err.code == 1) {
		console.log("Error: Access is denied!");
	}else if( err.code == 2) {
		console.log("Error: Position is unavailable!");
	}
}
setInterval(function(){
	if(navigator.geolocation){
		console.log("inside navigator")
		navigator.geolocation.getCurrentPosition(onPositionUpdate,errorHandler,{timeout:20000});
	}
	else
		alert("navigator.geolocation is not available");	
},1000);

The funtion will be called for every 1000msec i.e 1 second. Enable background support in "tizen" tab in config file.

Imgen Tata

Thanks.