you can achieve this with Google Maps JavaScript API v3 - Directions Service. There is a doc here. and you can see stand-alone google example here.
and in this doc. you can get information about Travel Modes.
When you calculate directions, you need to specify which
transportation mode to use. The following travel modes are currently
supported:
TravelMode.DRIVING indicates standard driving directions using the road network.
TravelMode.WALKING requests walking directions via pedestrian paths & sidewalks
(where available).
New! TravelMode.BICYCLING requests bicycling directions via bicycle paths & preferred
streets (currently only available in the US).
the Directions Service code:
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(41.850033, -87.6500523);
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: chicago
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
function calcRoute() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
routePath = result.routes[0].overview_path;
for(var a = 0; a< routePath.length; a++){
// Your vector layer to render points with line
}
directionsDisplay.setDirections(response);
}
});
}
The above code was taken from google api, i added some code there for you which you should have use used for your app.. main code for you is here:
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
routePath = result.routes[0].overview_path;
for(var a = 0; a< routePath.length; a++){
// Your vector layer to render points with line
}
directionsDisplay.setDirections(response);
}
});
i hope it helps you
Best Answer
Yes, that's possible using PostGIS with pgRouting and OpenLayers. You'll find an extensive tutorial here: http://pgrouting.org/docs/ol-workshop/index.html
In a similar question (routing using openlayers and pgrouting) the following GeoExt for pgRouting tutorial is recommended: http://workshop.pgrouting.org/chapters/geoext_client.html
You'll want to look into auto-complete scripts to support users when typing location names.
Finding nearest points on line has been discussed multiple times, e.g. Nearest neighbor between point layer and line layer?
You'll have to learn to write code ... or hire someone.