nauna says:
distance.Text = dsResult.Tables[
"duration"
].Rows[0][
"value"
].ToString() + dsResult.Tables[
"distance"
].Rows[0][
"text"
].ToString();
Replace the above line with below.
distance.Text = dsResult.Tables["distance"].Rows[0]["text"].ToString();
Check the below sample code.
HTML
<div>
duration;
<asp:TextBox runat="server" ID="duration" />
Distance:
<asp:TextBox ID="distance" runat="server" />
</div>
Namespaces
C#
using System.Net;
using System.IO;
using System.Text;
using System.Data;
VB.Net
Imports System.Net
Imports System.IO
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
string origin = "Oberoi Mall, Goregaon";
string destination = "Infinity IT Park, Malad East";
string url = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" + origin + "&destinations=" + destination + "&key=AIzaSyBE1J5Pe_GZXBR_x9TXOv6TU5vtCSmEPW4";
WebRequest request = WebRequest.Create(url);
using (WebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
DataSet dsResult = new DataSet();
dsResult.ReadXml(reader);
duration.Text = dsResult.Tables["duration"].Rows[0]["text"].ToString();
distance.Text = dsResult.Tables["distance"].Rows[0]["text"].ToString();
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim origin As String = "Oberoi Mall, Goregaon"
Dim destination As String = "Infinity IT Park, Malad East"
Dim url As String = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=" & origin & "&destinations=" & destination & "&key=AIzaSyBE1J5Pe_GZXBR_x9TXOv6TU5vtCSmEPW4"
Dim request As WebRequest = WebRequest.Create(url)
Using response As WebResponse = CType(request.GetResponse(), HttpWebResponse)
Using reader As StreamReader = New StreamReader(response.GetResponseStream(), Encoding.UTF8)
Dim dsResult As DataSet = New DataSet()
dsResult.ReadXml(reader)
duration.Text = dsResult.Tables("duration").Rows(0)("text").ToString()
distance.Text = dsResult.Tables("distance").Rows(0)("text").ToString()
End Using
End Using
End Sub