0

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>
2
Contributors
2
Replies
17
Views
3 Years
Discussion Span
Last Post by DJBirdi
1

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>
0

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!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.