// CONFIG (Move to different file)
var endpoint = {
  points: 'points'
};

var appUrl = 'http://localhost:3000/api/';

// END CONFIG

var request = function (options) {
  var xhr = new XMLHttpRequest();
  xhr.open(options.method, options.url);
  xhr.setRequestHeader('Content-Type', 'application/json');
  xhr.addEventListener('load', options.callback);
  xhr.send(JSON.stringify(options.data || {}));
};
///////////////////////////////////////////////////

function initialize() {
  var mapCanvas = document.getElementById('map_canvas');
  var mapOptions = {
    center: new google.maps.LatLng(44.5403, -78.5463),
    zoom: 8,
    mapTypeId: google.maps.MapTypeId.HYBRID
  };
  var map = new google.maps.Map(mapCanvas, mapOptions);
}

function submitLocation(data, cb) {
  var options = {
    method: 'POST',
    url: appUrl + endpoint.points,
    data: data,
    callback: cb
  };
  request(options);
}

if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(
    function(position) {
    var callback = function(event) {
      console.log(event);
    };
    var data = {
      name: new Date().toString(),
      coordinates: [position.coords.latitude, position.coords.longitude]
    };
    submitLocation(data, callback);
  },
  function(error) {
    console.log(error);
  },{ timeout: 30000, enableHighAccuracy:false}
  );
} else {
  console.log('Permission denied');
}

google.maps.event.addDomListener(window, 'load', initialize);

@@ -332,24 +332,89 @@
 d', 
-options.callback
+function(event)%7B%0A    options.callback(JSON.parse(event.target.responseText));%0A  %7D
 );%0A 
@@ -791,16 +791,36 @@
 tions);%0A
+  window.map = map;%0A
 %7D%0A%0Afunct
@@ -1110,21 +1110,20 @@
 unction(
-event
+data
 ) %7B%0A    
@@ -1128,25 +1128,115 @@
     
-console.log(event
+var loc = new google.maps.LatLng(data.loc.coordinates%5B0%5D, data.loc.coordinates%5B1%5D);%0A      map.setCenter(loc
 );%0A 
@@ -1563,57 +1563,8 @@
 %0A%7D%0A%0A
-google.maps.event.addDomListener(window, 'load', 
 init
@@ -1569,11 +1569,12 @@
 itialize
+(
 );%0A

Set to users location