var map, directionsDisplay, pos;
var directionsService = new google.maps.DirectionsService();

function initialize() {
  var mapOptions = {
    zoom: 18
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  // Try HTML5 geolocation
  if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      pos = new google.maps.LatLng(position.coords.latitude,
                                  position.coords.longitude);
      var infowindow = new google.maps.InfoWindow({
        map: map,
        position: pos
      });

      // var marker = new google.maps.Marker({
      //   position: pos,
      //   map: map,
      //   draggable: true,
      //   title: 'Your Position'
      // });

      map.setCenter(pos);

      // google.maps.event.addListener(marker, "dragend", function(event) {
      //   var lat = event.latLng.k;
      //   var lng = event.latLng.B;
      //   updateMap(lat, lng);
      // });
    google.maps.event.addListener(map, 'tilesloaded', function(){
      // Map has loaded
      console.log('Done Loading');
    });
  }, function() {
    handleNoGeolocation(true);
    });
  } else {
    // Browser doesn't support Geolocation
    handleNoGeolocation(false);
  }

  function handleNoGeolocation(errorFlag) {
    if (errorFlag) {
      var content = 'Error: The Geolocation service failed.';
    } else {
      var content = 'Error: Your browser doesn\'t support geolocation.';
    }

    var options = {
      map: map,
      position: new google.maps.LatLng(60, 105),
      content: content
    };

    var infowindow = new google.maps.InfoWindow(options);
    map.setCenter(options.position);
  }

  var rendererOptions = {draggable: true};

  directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
  directionsDisplay.setMap(map);
  directionsDisplay.setPanel(document.getElementById('directions'));
}

function updateMap(latitude, longitude) {
  centerAt = new google.maps.LatLng(latitude, longitude);
  map.setCenter(centerAt);
  addToForm(latitude, longitude);
}

function calcRoute() {
  setTimeout(function() {
    var $end = $('#end').val();
    var parsedEnd = parseCoordinates($end);
    var end = new google.maps.LatLng(parsedEnd[0], parsedEnd[1]);

    var request = {
      origin: pos,
      destination: end,
      travelMode: google.maps.TravelMode.WALKING
    };

    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
  }, 4000);
}

function parseCoordinates(coord) {
  var separateCoord = coord.split(", ");
  separateCoord[0] = separateCoord[0].replace("(", "");
  separateCoord[1] = separateCoord[1].replace(")", "");
  var finalCoord = [parseFloat(separateCoord[0]),
                    parseFloat(separateCoord[1])];
  return finalCoord;
}

google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addDomListener(window, 'load', calcRoute);
@@ -24,16 +24,33 @@
 lay, pos
+, rendererOptions
 ;%0Avar di
@@ -606,178 +606,8 @@
 );%0A%0A
-      // var marker = new google.maps.Marker(%7B%0A      //   position: pos,%0A      //   map: map,%0A      //   draggable: true,%0A      //   title: 'Your Position'%0A      // %7D);%0A%0A
     
@@ -634,19 +634,16 @@
 ;%0A%0A     
- //
  google.
@@ -671,23 +671,24 @@
 r(ma
-rker, %22dragend%22
+p, 'tilesloaded'
 , fu
@@ -698,15 +698,9 @@
 ion(
-event) 
+)
 %7B%0A  
@@ -710,251 +710,309 @@
  // 
-  var lat = event.latLng.k;%0A      //   var lng = event.latLng.B;%0A      //   updateMap(lat, lng);%0A      // %7D);%0A    google.maps.event.addListener(map, 'tilesloaded', func
+Map has loaded%0A      console.log('Done Loading');%0A    %7D);%0A%0A    rendererOptions = %7Bdraggable: true%7D;%0A    directionsDisplay = new google.maps.DirectionsRenderer(rendererOp
 tion
-()%7B
+s);
 %0A    
-  // Map has loaded%0A      console.log('Done Loading');%0A    %7D
+directionsDisplay.setMap(map);%0A    directionsDisplay.setPanel(document.getElementById('directions'));%0A    calcRoute(
 );%0A
+%0A
   %7D,
@@ -1593,230 +1593,8 @@
 %0A  %7D
-%0A%0A  var rendererOptions = %7Bdraggable: true%7D;%0A%0A  directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);%0A  directionsDisplay.setMap(map);%0A  directionsDisplay.setPanel(document.getElementById('directions'));
 %0A%7D%0A%0A
@@ -1784,36 +1784,8 @@
 ) %7B%0A
-  setTimeout(function() %7B%0A  
   va
@@ -1808,26 +1808,24 @@
 ').val();%0A  
- 
- 
 var parsedEn
@@ -1852,18 +1852,16 @@
 ($end);%0A
-  
   var en
@@ -1917,18 +1917,16 @@
 d%5B1%5D);%0A%0A
-  
   var re
@@ -1939,18 +1939,16 @@
 = %7B%0A    
-  
 origin: 
@@ -1952,18 +1952,16 @@
 n: pos,%0A
-  
     dest
@@ -1978,18 +1978,16 @@
 nd,%0A    
-  
 travelMo
@@ -2021,26 +2021,24 @@
 WALKING%0A
-  
   %7D;%0A%0A  
   direct
@@ -2029,18 +2029,16 @@
   %7D;%0A%0A  
- 
- 
 directio
@@ -2095,18 +2095,16 @@
 ) %7B%0A    
-  
 if (stat
@@ -2150,18 +2150,16 @@
 %7B%0A      
- 
- 
 directio
@@ -2201,29 +2201,13 @@
     
+%7D%0A
   %7D
-%0A    %7D);%0A  %7D, 4000
 );%0A%7D
@@ -2586,65 +2586,4 @@
 ze);
-%0Agoogle.maps.event.addDomListener(window, 'load', calcRoute);

Remove timeout function