Created
January 14, 2013 16:21
-
-
Save KoryNunn/4531223 to your computer and use it in GitHub Desktop.
Gets the users position, caching requests between position checks. Solves huge lag issue in chrome for android.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var requestCallbacks = [], | |
| ready = true; | |
| function getPosition(callback){ | |
| requestCallbacks.push(callback); | |
| if(ready){ | |
| ready = false; | |
| navigator.geolocation.getCurrentPosition(function(position){ | |
| while(requestCallbacks.length){ | |
| requestCallbacks.pop()(position); | |
| } | |
| ready = true; | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment