I'm kind of a javascript noob, and I'm trying to use the new geolocation API in Firefox 3.5 to get an estimation of the user's coordinates and put that into a text box in a form. What I have doesn't seem to be working; it seems like the boxes are filled before the location is actually retreived. Here's what I have so far:
<html>
<head>
<script type="text/javascript">
var lati =0;
var longi =0;
function getPosition(position)
{
lati = position.coords.latitude;
longi = position.coords.longitude;
}
function writeLati(form)
{
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(getPosition);
lati = position.coords.latitude;
longi = position.coords.longitude;
form.latitude.value = lati;
form.longitude.value = longi;
} else {
form.latitude.value = "3";
form.longitude.value = "5";
document.write("Your shitty browser can't do geolocation. Get Firefox 3.5.");
}
}
</script>
</head>
<body onLoad="writeLati(locform)">
<form name="locform" action="submit.php" method="post" >
Latitude: <input type="text" name="latitude" value=""/>
Longitude: <input type="text" name="longitude" value="" />
Gender: <input type="radio" name="gender" value="Male" /> Male <input type="radio" name="gender" value="Female" checked="checked" /> Female
<input type="submit" />
</form>
</body>