var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var startlatlng = new google.maps.LatLng(50.067, -5.717);
var endlatlng = new google.maps.LatLng(58.633, -3.067);
var map;
function init() {
directionsDisplay = new google.maps.DirectionsRenderer();
var latlng = new google.maps.LatLng(54.6, -4.25);
var myOptions = { zoom: 6, center: latlng, disableDefaultUI: true, mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
calcRoute();
}
function calcRoute() {
var request = {
origin: startlatlng,
destination: endlatlng,
avoidHighways: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
google.maps.event.addDomListener(window, 'load', init);