title: Google Maps - directions from users geo-location
body: <p>I have the following function that checks if the browser supports geo-location and then gets the users geo-location and centres it on the map.</p>
  
  <p>What do I need to add to allow me to give the users direction to a fixed location (this won't change) from the users geo-location?</p>
  
  <pre><code>if (navigator.geolocation)
  {
    navigator.geolocation.getCurrentPosition(function(position)
    {                                                              
      var latitude = position.coords.latitude;                    
      var longitude = position.coords.longitude;                 
      var coords = new google.maps.LatLng(latitude, longitude);
      var directionsDisplay;
      var directionsService = new google.maps.DirectionsService();
      var mapOptions = 
      {
        zoom: 15,  
        center: coords, 
        mapTypeControl: true, 
        navigationControlOptions:
        {
          style: google.maps.NavigationControlStyle.SMALL
        },
         mapTypeId: google.maps.MapTypeId.ROADMAP
      };
       map = new google.maps.Map(document.getElementById("mapContainer"), mapOptions);
       var marker = new google.maps.Marker( 
         {
           position: coords, 
           map: map,                 
          });
     });
  }
  else
  {
     alert("Geolocation API is not supported in your browser.");
  </code></pre>
  
  <p>I've added this function to my code:</p>
  
  <pre><code>  function calcRoute() {
      var start = position;
      var end = "London";
      var request = {
        origin: start,
        destination: end,
        travelMode: google.maps.TravelMode.DRIVING
      };
      directionsService.route(request, function (result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
          directionsDisplay.setDirections(result);
        }
      });
    }
  </code></pre>
  
  <p>HTML:
  <code>&lt;div id="mapContainer" onload="calcRoute()"&gt;&lt;/div&gt;</code></p>
  
  <p>But it still does not seem to be working.</p>