Posted By

Piotrek290 on 06/21/11


Tagged

class geolocation


Versions (?)

Geolocation


 / Published in: JavaScript
 

  1. // CLASS
  2. var Geolocation = Class.extend({
  3. init : function(options){
  4. var on = {
  5. success : options.success||function(){},
  6. error : options.error||function(){},
  7. set : options.set||{}
  8. };
  9.  
  10. navigator.geolocation.watchPosition(on.success, on.error, on.set);
  11. }
  12. });
  13.  
  14.  
  15. // USE
  16. var geolocation = new Geolocation({
  17. set : {
  18. enableHighAccuracy : true,
  19. maximumAge : 8000 // 8 sec.
  20. },
  21.  
  22. success : function(geo){
  23. var coords = geo.coords;
  24. var nd = "brak informacji";
  25.  
  26. get("geo_latitude", coords.latitude||nd);
  27. get("geo_longitude", coords.longitude||nd);
  28. get("geo_speed", coords.speed||nd);
  29. get("geo_altitude", coords.altitudeAccuracy||nd);
  30. get("geo_timestamp", geo.timestamp||nd);
  31. },
  32.  
  33. error : function(error){
  34. switch(error.code){
  35. case error.PERMISSION_DENIED:
  36. alert("user did not share geolocation data");
  37. break;
  38.  
  39. case error.POSITION_UNAVAILABLE:
  40. alert("could not detect current position");
  41. break;
  42.  
  43. case error.TIMEOUT:
  44. alert("retrieving position timedout");
  45. break;
  46.  
  47. default:
  48. alert("unknown error");
  49. }
  50. }
  51. });

Report this snippet  

You need to login to post a comment.