I am creating a web app using geolocation. So far I have it set up and working so when the user visits they are prompted to allow location services, then are presented with an alert (Not permanent, just for testing purposes.)
I am using this:
navigator.geolocation.getCurrentPosition(foundLocation, noLocation, {enableHighAccuracy:true});
function foundLocation(position)
{
var lat = position.coords.latitude;
var long = position.coords.longitude;
alert('We know you are here '+ lat +','+ long);
}
function noLocation()
{
alert('Could not find location');
}
Then I have a variable outside this called "address" which is the URL for the API call:
address = "http://api.wunderground.com/api/geolookup/hourly/conditions/astronomy/alerts/forecast/q/[LOCATION].json"
My question is how can I get the lat
and long
out of the function and insert them into the URL? I have tried a few methods, but they all return "undefined" so I am obviously doing something wrong.
Any help is greatly appreciated!
Thank you.