Created
August 25, 2013 19:54
-
-
Save jswhisperer/6335913 to your computer and use it in GitHub Desktop.
Basic Geolocation API namespaced
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 Geo = {}; | |
| Geo.positionOptions = { | |
| enableHighAccuracy: true, | |
| timeout: 5000, | |
| maximumAge: 30000 | |
| } | |
| Geo.error = function(positionError) { | |
| var code = positionError.code, | |
| message = positionError.message, | |
| errorCode = { | |
| 1: 'permission denied', | |
| 2: 'position unavailable', | |
| 3: 'timeout' | |
| }; | |
| code = errorCode[code]; | |
| //console.log(message + ' ' + code) | |
| }; | |
| Geo.callback = function(position) { | |
| var latitude = position.coords.latitude, | |
| longitude = position.coords.longitude, | |
| altitude = position.coords.altitude, | |
| altitudeAccuracy = position.coords.altitudeAccuracy, | |
| heading = position.coords.heading, | |
| speed = position.coords.speed, | |
| timestamp = position.timestamp; | |
| //console.log(position); | |
| }; | |
| Geo.get_location = function() { | |
| navigator.geolocation.getCurrentPosition(Geo.callback, Geo.error, Geo.positionOptions); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment