Is there a listner to check if the GPS signal is back/available
Dear All,
I am searching since a while how check is GPS is available after having lost the signal.
I am using that code to watch my position
- if($('#googleAPI').length != 0){
//var track_id = "me";
if (Tracking.watch_id == null) {
Tracking.watch_id = navigator.geolocation.watchPosition(
// Success
function(position){
var lat = position.coords.latitude;
var long = position.coords.longitude;
var latLng = new Array();
latLng[0] = lat;
latLng[1] = long;
//Tracking.myCoordinates.push(lat,long);
Tracking.myCoordinates.push(latLng);
addMarker(lat, long);
Alert.show('Watch called' + lat + '/' + long);
},
// Error
showError,
{
frequency: 1000
});
console.log('HW : WatchPosition called. Id:' + Tracking.watch_id);
}
}else{
Alert.show('The map API has not been loaded. Check for connection and try again. (pagebeforeshow)');
}
Also when I leave my #home page, I clean the watch event
- $('#home').live("pagebeforehide", function() {
if($('#googleAPI').length != 0){
//track_id = "me";
// Stop tracking the user
if (Tracking.watch_id != null) {
navigator.geolocation.clearWatch(Tracking.watch_id);
console.log('HW : WatchPosition cancelled Id:' + Tracking.watch_id);
Tracking.watch_id = null;
}
//navigator.geolocation.clearWatch(Tracking.watch_id);
//Tracking.watch_id = null;
Tracking.myCoordinates = new Array();
}else{
Alert.show('The map API has not been loaded. Check for connection and try again. (pagebeforeshide)');
}
});
My problem is when I go through a tunnel where the satelite is not available.
Then GPS icon of my smartphone disapear.
The problem is when I leave the tunnel, the watch do not continue because the GPS is not active. I have to move to another page and return to home to see teh GPS icon and then the watch event retart.
Is there a way to "listner" the GPS signal?
On my above code
- Tracking.watch_id = navigator.geolocation.watchPosition(
// Success
function(position){
var lat = position.coords.latitude;
var long = position.coords.longitude;
var latLng = new Array();
latLng[0] = lat;
latLng[1] = long;
//Tracking.myCoordinates.push(lat,long);
Tracking.myCoordinates.push(latLng);
addMarker(lat, long);
Alert.show('Watch called' + lat + '/' + long);
},
// Error
showError,
{
frequency: 1000
});
console.log('HW : WatchPosition called. Id:' + Tracking.watch_id);
}
the showErro(9 function works when I lunch the #home page, but when the #home is active and I loose the GPS, the showError() function is not called, even after the frequency of 1sec. I think it 's normal because the
navigator.geolocation.watchPosition() even can not be fired because the is no GPS, and then, no new position can be detected
Is there a way to solve that issue?
by the way, I thought to have a refresh button, but I realy can not find how to refresh manualy the same page.
Is there a simple code for that? I already test a lost of different solution, but nothing helped me.
Many thank for your help.
Cheers