/** casperjs-geolocation
  * A capser module that mocks the geolocation API
  */

// functions to be evaluated in remote
var Remote = {
  add_geolocation_api : function(pos) {
    navigator.geolocation = {
      // store pos here
      __casperFakeLocation : pos,
      
      // getcurrentposition
      getCurrentPosition : function(callback, err) {
        callback({coords : this.__casperFakeLocation});
      },

      // stores the callback passed to watchPosition
      __casperWatchCallback : undefined,

      // watchposition
      watchPosition : function(callback) {
        this.__casperWatchCallback = callback;
        console.log('watchPosition called');
        callback(this.__casperFakeLocation);
      }
    };
  },

  update_position : function(pos) {
    navigator.geolocation.__casperFakeLocation = pos;
    if(navigator.geolocation.__casperWatchCallback) {
        navigator.geolocation.__casperWatchCallback(pos);
    }
  }
};

// module
var Geolocation = function(casper, pos) {
  this._pos = pos || {longitude : 0, latitude : 0};
  this._casper = casper;
};

Geolocation.prototype.getPos = function () {
  return this._pos
};

Geolocation.prototype.setPos = function(pos) {
  this._pos = pos;
  this._casper.evaluate(Remote.update_position, {
    timestamp: Date.now(),
    coords: {
      longitude: pos.longitude,
      latitude: pos.latitude
    }
  });
};

module.exports = function(casper, pos) {
  var geo = new Geolocation(casper, pos);
  casper.on('page.initialized', function() {
    geo._casper.evaluate(Remote.add_geolocation_api, pos);
  });
  return geo;
}


@@ -358,26 +358,66 @@
    c
-allback(%7Bcoords : 
+onsole.log('getCurrentPosition called');%0A        callback(
 this
@@ -437,17 +437,16 @@
 Location
-%7D
 );%0A     
@@ -1059,16 +1059,64 @@
 pos %7C%7C %7B
+%0A    timestamp: Date.now(),%0A    coords: %7B%0A      
 longitud
@@ -1120,22 +1120,28 @@
 tude
- 
 : 0, 
+%0A      
 latitude
  : 0
@@ -1140,12 +1140,40 @@
 tude
- 
 : 0
+, %0A      accuracy: 0%0A    %7D%0A  
 %7D;%0A 
@@ -1485,16 +1485,52 @@
 latitude
+,%0A      accuracy: pos.accuracy %7C%7C 10
 %0A    %7D%0A 

add accuracy parameter, make getCurrentPosition and watchPosition return the same data