document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
geo();
}
function geo(){
alert("latitude:" + latitude + "longitude:" + longitude);
$('#latitude-input').val(latitude);
$('#longitude-input').val(longitude);
};
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
I don't want users to control app until it figures out latitude and longitude. I want them to wait for loading watching splash screen instead.
And I have one more question. Is phonegap able to know whether GPS is turned on? I think the function onError should make alert message, but it doesn't.
@jerome, It is possible to do what you are asking, but it might be a looong time before that splash screen goes away. GPS does not work that way. I suggest you do a lot of reading GPS. Your misconception is common. I'm sorry I do not have any good articles for you to read. This is article may be to technical for you, but try it Garmin | What is GPS?
In the meantime, you can get what you need to try with my demo Apps.
Phonegap Demo Apps
http://codesnippets.altervista.org/examples/phonegap/demos/PUBLIC.Apps.html
You will want to combine:
Then go to the config.xml for the splash screen and remove the delay. This line:
Lastly, on your question, if the GPS is turned off, and frequently it is because it drains the battery very quickly, the onError() callback will time out. To be clear, you cannot detect if it is on. When you try to get GPS information, you will on get an error telling you that it did not respond in time. (It is a bad design, but that is how it works.)