Hello,
I am trying to "transfer" geolocation-data to a php script.
I think, that the reason it wont work is, i can't get the varible from outside the function.

So far, i got this code.
How do i get it to work?! :)

<body onload="office_getLocation()">
<script src="min.js" type="text/javascript"></script>
<script type="text/javascript">
function office_getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
}

function showPosition(position)
{
var lat = position.coords.latitude; 
var lon = position.coords.longitude;
}

 $(function() {
     getStatus();
 });
 function getStatus() {
     $('div#status').load("upload.php?la=" . lat . "&lo=" . lon);
    setTimeout("getStatus()",1000);
}

</script>
 <div id="status"></div>
</body>

Okey,

i got it solved

<body onload="office_getLocation()">
<script src="min.js" type="text/javascript"></script>
<script type="text/javascript">
function office_getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.watchPosition(showPosition);
}
}
 $(function() {
     showPosition();
 });
 function showPosition(position) {
var lat = position.coords.latitude; 
var lon = position.coords.longitude;
var done = "upload.php?la=" + lat + "&lo=" + lon;
     $('div#status').load(done);
    setTimeout("showPosition()",1000);
}
</script>
 <div id="status"></div>
</body>

Now grab a beer and say this to yourself: I don't always solve my own problems, but when I do, I DO IT LIKE A BOSS!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.