<%--
--%>
From:
<%----%>
To:
<%----%>
<%----%>
Start Value
End Value
Distance
Total Fare
<%--£--%>
 
public partial class Pickup3 : System.Web.UI.Page
{
string dkm, ds, distance;
string origin, destination;
double conv = 0.62137;
double miles, d2;
string xmlResult = null;
XmlDocument doc = new XmlDocument();
static int Taxicount;
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
//double dist = Convert.ToDouble(Session["taxi_distance"]);
double veh = Convert.ToDouble(Session["taxi_vehicle"]);
//startvalue2.Text = Session["taxi_origin"].ToString();
//endvalue2.Text = Session["taxi_destination"].ToString();
}
}
protected void Button2_Click1(object sender, EventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" + startvalue.Text + "&destinations=" + endvalue.Text + "&mode=Car&language=us-en&sensor=false");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader resStream = new StreamReader(response.GetResponseStream());
xmlResult = resStream.ReadToEnd();
doc.LoadXml(xmlResult);
try
{
if (doc.DocumentElement.SelectSingleNode("/DistanceMatrixResponse/row/element/status").InnerText.ToString().ToUpper() != "OK")
{
//Response.Write("");
return;
}
XmlNodeList xnList = doc.SelectNodes("/DistanceMatrixResponse");
foreach (XmlNode xn in xnList)
{
if (xn["status"].InnerText.ToString() == "OK")
{
dkm = doc.DocumentElement.SelectSingleNode("/DistanceMatrixResponse/row/element/distance/text").InnerText;
ds = dkm.Replace("km", " ");
distance = ds.Trim();
d2 = Convert.ToDouble(distance);
// miles = conv * d2;
origin = xn["origin_address"].InnerText.ToString();
destination = xn["destination_address"].InnerText.ToString();
Session.Add("taxi_origin", origin);
Session.Add("taxi_destination", destination);
// Session.Add("taxi_distance", miles);
Session.Add("shams", "Return Date and Time");
//Session.Add("taxi_cartype", Rdb_CarType.SelectedValue);
//double dist = Convert.ToDouble(Session["taxi_distance"]);
double veh = Convert.ToDouble(Session["taxi_vehicle"]);
//Lbl_Distance.Text = Math.Round(dist, 2).ToString() + " miles";
// Lbl_Fare.Text = Math.Round(dist * 2.5 * veh, 2).ToString();
string a = "1";
Session.Add("BookTaxi", a);
Taxicount++;
Session.Add("TaxiCount", Taxicount.ToString());
if (Session["taxi_oneway"] == "One Way")
{
//Lbl_Distance.Text = Math.Round(dist, 2).ToString() + " miles";
// Lbl_Fare.Text = Math.Round(dist * 2.5 * veh, 2).ToString();
}
Session.Add("totalfare", Lbl_Fare.Text);
//Session.Add("totaldistance", Lbl_Distance.Text);
}
}
}
catch
{
Response.Write("");
return;
}
}
}
These are my codes how to calculate fare of between origin and destination as per kilometer plz help guys