Why are my variables not declaring outside a function

What im trying to do here is get the coordinates data from the html5 geolocation feature and declaring them to variables so that i can manipulate them. but for some reason when i go outside the function the values are undefined. Got any ideas on how I can combat this???help

The getCurrentPosition API call is made asynchronously, so even though lat an long are declared globally outside your function, the console.log statements are executed before a response comes back from the getCurrentPosition API.