GoogleMaps Directions from 2 points
HTML
<script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<div id="map_canvas" style="height: 400px; width: 600px"></div>
JavaScript
var directionDisplay;
var directionsService = new google.maps.DirectionsService(); //Create a DirectionsService object which is required to communicate with the Google Maps API Direction Service
var map;
directionsDisplay = new google.maps.DirectionsRenderer(); //Create a DirectionsRenderer object to render the directions results
var center = new google.maps.LatLng(0, 0); //Map is centered at 0,0
var myOptions =
{
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: center
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
var start = "106 applegreen Ln, Lakeway, TX"; //Set the source/ origin
var end = "3301 Serene Hills Dr, Austin, TX"; //Set the destination
var request =
{
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING //Current travel mode is DRIVING. You can change to BICYCLING or WALKING and see the changes.
};
directionsService.route(request, function(response, status)
{
if (status == google.maps.DirectionsStatus.OK) //Check if request is successful.
{
directionsDisplay.setDirections(response); //Display the directions result
}
});