I'm having some trouble with function callbacks, specifically with the HTML5 geolocation API. I'm a little new to Js as well. The function:
function getInfo()
{
navigator.geolocation.getCurrentPosition(getPos);
}
takes a callback parameter of a function that gets the position passed into it.
function getPos(position)
{
PositionObj.lat = position.coords.latitude;
PositionObj.lon = position.coords.longitude;
}
I created a "location" object to store the coordinates, and I'm having trouble returning them.
var PositionObj =
{
lat:null,
lon:null,
returnLat: function()
{
return this.lat;
},
returnLon: function()
{
return this.lon;
}
};
function printStuff()
{
getInfo();
console.log(PositionObj.returnLat());
}
EDIT: Syntax mistakes fixed. When I call printStuff(), I still get "null."