Take a look at the Google Maps API documentation. Here is the section on
drawing lines.
But this should work:
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(lat1, lng1), 15);
var polyOptions = {geodesic:true};
var polyline = new GPolyline([
new GLatLng(lat1, lng1),
new GLatLng(lat2, lng2)
], "#ff0000", 10, 1, polyOptions);
map.addOverlay(polyline);
map.setUIToDefault();
var marker1 = new GMarker(new GLatLng(lat1, lng1));
map.addOverlay(marker1);
var marker2 = new GMarker(new GLatLng(lat2, lng2));
map.addOverlay(marker2);
}
Also, consider upgrading your code and using version
3 of the Maps API