I am using navigator.geolocation.getCurrentPosition (function) api in firefox 3.6. When I try to name this method many times, I see that sometimes it works, and sometimes not. I realized that the problem is with its asynchronous callback. I see that the callback function is being called at some point, but my external function is already exiting, so I cannot catch the position coordinates.
I'm new to javascript, so I guess other javascript coders might already figure out how to deal with this. Please, help.
Edit: here is the sample 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; </script>
Edit 2: Thanks everyone for the answer, I would like all the answers to be โacceptedโ, but cannot do this.
Now I am facing another problem. I call navigator.geolocation.getCurrentPosition every 3 seconds, but the answers stop after 10-15 answers. Anyone got it?
thanks again
source share