I am new to Java scripting and need quick help. Here is my code:
<html>
<head>
<title> GeoLocation Application </title>
<script>
$counter=0;
while ($counter < 10) {
if (!navigator.geolocation) {
alert('Your browser does not support geolocation');
} else {
navigator.geolocation.getCurrentPosition(success, error);
document.write("Count ",$counter,"<br>");
}
$counter ++;
}
function success(position) {
lat = position.coords.latitude;
lng = position.coords.longitude;
alert (lat +','+lng);
document.write("calling update mysql");
//document.location='update_java_data.php?lat=' + lat+'&lng='+lng;
}
function error(error) {
alert('an erro occured, error code is '+error);
}
</script>
</head>
<body>
<h1> Hello </h1>
</body>
</html>
I am trying to get coordinates using navigator 10 times. But when I am seeing only a quick list of counter display from 0 to 9, but only once it displays “”calling update mysql”.
To me it means it only executed success function once.
Any idea how I can make it get the coordinate 10 times (means it should also call success function 10 times I guess)?
I would suggest instead looking at using the setInterval function to do your lat/long collection at specified intervals… If what you have above runs successfully, it would probably collect the same point 10 times quickly.
So, since you do those function calls without any type of a wait/interval, they all fire off at basically the same time (0-9 counter display)… As for only seeing the ‘calling update mysql’ once, I would imagine that it has something to do with you changing the location of the window to a different url, and the other calls not being able to reach the success function since you have already mo