I would like to be able to take the value of the variable lat out of the function, to put it in a form. In this case, I just wanted to take out an alert (lat), but it does not work. Or it shows everything or nothing, but only lat no.
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
navigator.geolocation.getCurrentPosition(onSuccess, onError);
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />';
var lat = position.coords.latitude;
var lon = position.coords.longitude;
}
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
</head>
<body>
<p id="geolocation">Finding geolocation...</p>
<script>alert (lat);</script>
</body>
</html>