Hi all
I'm using the navigator.geolocation.getCurrentPosition(function) api in firefox 3.6. When i try to call this method repeatedly I see that sometimes it works and sometimes it doesn't. I figured that the problem is because of its asynchronous callback nature. I can see that the callback function is being called at some point but my outer function is already exiting so i cannot catch the values of the position coordinates.
I'm pretty new to javascript so i'm assuming other javascript coders might have already figured out how to deal with it. Please help.
Edit: here's a sample piece of code i'm using
<script type="text/javascript">
function getCurrentLocation() {
var currLocation;
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
currLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
});
}
return currLocation; // this returns undefined sometimes. I need help here
}
</script>
Edit 2: Thanks everyone for answering, I wish i could choose all the answers as "accepted" but cannot do so.
Now I'm facing another problem. I'm calling the navigator.geolocation.getCurrentPosition every 3 seconds, but the responses stop after 10 - 15 replies. Any one got any idea ?
thanks again