The current script works:
<code>
window.onload = init;
function init() {
var onSuccess = function(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + new Date(position.timestamp) + '\n');
};
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
};
</code>
What I don't understand is how the getCurrentPosition function provides onSuccess with an object to the parameter. How is the position parameter given an object to work with by getCurrentPosition?
I am not sure how I would do this with creating my own functions - perhaps a simple piece of code that shows this working would be what I need.
I have searched for this and have been unable to find the answer.
Thanks,
<code>
window.onload = init;
function init() {
var onSuccess = function(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude + '\n' +
'Altitude: ' + position.coords.altitude + '\n' +
'Accuracy: ' + position.coords.accuracy + '\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' +
'Heading: ' + position.coords.heading + '\n' +
'Speed: ' + position.coords.speed + '\n' +
'Timestamp: ' + new Date(position.timestamp) + '\n');
};
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
};
</code>
What I don't understand is how the getCurrentPosition function provides onSuccess with an object to the parameter. How is the position parameter given an object to work with by getCurrentPosition?
I am not sure how I would do this with creating my own functions - perhaps a simple piece of code that shows this working would be what I need.
I have searched for this and have been unable to find the answer.
Thanks,