Reputation: 357
I'm trying to show (on alert) a position of GPS using Phonegap when I call other function, but it doesn't work at all.
My code:
var lat=0.0;
var lon=0.0;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
function onSuccess(position) {
lat = position.coords.latitude;
lon = position.coords.longitude;
}
function ShowPosition(){
alert("Latitude: "+lat+" longitude: "+lon);
}
EDIT: The showPosition function is called on "onclick" event on a button of my HTML code
Upvotes: 0
Views: 935
Reputation: 928
you have to call ShowPosition() function somewhere, in your code you never called this function. that's the issue, your code is perfect.
hope this may help you. thanks.
Upvotes: 1