Created
February 7, 2012 10:16
-
-
Save tejo/1758953 to your computer and use it in GitHub Desktop.
geocation class
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
| GeoLocator = (function() { | |
| function GeoLocator() { | |
| this.watch = __bind(this.watch, this); this.watcher = navigator.geolocation.watchPosition(this.watch, this.geo_error, { | |
| enableHighAccuracy: true, | |
| frequency: 3000, | |
| maximumAge: 2000, | |
| timeout: 27000 | |
| }); | |
| this.map = new Map(document.getElementById("map")); | |
| } | |
| GeoLocator.prototype.watch = function(position) { | |
| this.coords = position.coords; | |
| if (this.coords.accuracy > 50) { | |
| return $("#geolocation").html("getting location"); | |
| } else { | |
| if (this.map.map_visible) { | |
| this.map.moveMarker(this.coords); | |
| this.map.center(this.coords); | |
| } else { | |
| this.map.init(this.coords); | |
| } | |
| return $("#geolocation").html("Latitude: " + this.coords.latitude + "<br />Longitude: " + this.coords.longitude + " <br />Accuracy: " + this.coords.accuracy + "<br />"); | |
| } | |
| }; | |
| GeoLocator.prototype.geo_error = function() { | |
| return alert("geolocation not available"); | |
| }; | |
| GeoLocator.prototype.stop = function() { | |
| return navigator.geolocation.clearWatch(this.watcher); | |
| }; | |
| return GeoLocator; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment