Tuesday, November 16, 2010

Google map api total distance and duration calculation C#

Google map api total distance and duration calculation between from address and to address.
 
 
protected void Page_Load(object sender, EventArgs e)

{

XmlDocument xDoc = new XmlDocument();

xDoc.Load("http://maps.googleapis.com/maps/api/directions/xml?origin=92610&destination=92630&sensor=false");

XmlNodeList xnList = xDoc.SelectNodes("DirectionsResponse/route/leg/distance");

foreach (XmlNode xn in xnList)

{

Response.Write("distance-> "+xn["text"].InnerText);

}

XmlNodeList xnList1 = xDoc.SelectNodes("DirectionsResponse/route/leg/duration");

foreach (XmlNode xn in xnList1)

{

Response.Write("<br>duration-> " + xn["text"].InnerText);

}

}

No comments: