Hi nauna,
I have created a sample which full fill your requirement you need to modify the code according to your need.
HTML
<table>
<tr>
<td>
Origin Address:
</td>
<td>
<asp:Label ID="lblOriginAddress" runat="server" />
</td>
</tr>
<tr>
<td>
Destination Address:
</td>
<td>
<asp:Label ID="lblDestinationAddress" runat="server" />
</td>
</tr>
<tr>
<td>
Duration Text:
</td>
<td>
<asp:Label ID="lblDurationText" runat="server" />
</td>
</tr>
<tr>
<td>
Duration Value:
</td>
<td>
<asp:Label ID="lblDurationValue" runat="server" />
</td>
</tr>
<tr>
<td>
Distance Text:
</td>
<td>
<asp:Label ID="lblDistanceText" runat="server" />
</td>
</tr>
<tr>
<td>
Distance Value:
</td>
<td>
<asp:Label ID="lblDistanceValue" runat="server" />
</td>
</tr>
</table>
C#
protected void Page_Load(object sender, EventArgs e)
{
string url = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=SE9%204QH&destinations=BR7%205QP&key=AIzaSyBojHBt73ZegOGb2Kj8boi0HXMKRyfftVg";
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);
lblOriginAddress.Text = dsResult.Tables["DistanceMatrixResponse"].Rows[0]["origin_address"].ToString();
lblDestinationAddress.Text = dsResult.Tables["DistanceMatrixResponse"].Rows[0]["destination_address"].ToString();
lblDurationText.Text = dsResult.Tables["duration"].Rows[0]["text"].ToString();
lblDurationValue.Text = dsResult.Tables["duration"].Rows[0]["value"].ToString();
lblDistanceText.Text = dsResult.Tables["distance"].Rows[0]["text"].ToString();
lblDistanceValue.Text = dsResult.Tables["distance"].Rows[0]["value"].ToString();
}
}
}
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim url As String = "https://maps.googleapis.com/maps/api/distancematrix/xml?origins=SE9%204QH&destinations=BR7%205QP&key=AIzaSyBojHBt73ZegOGb2Kj8boi0HXMKRyfftVg"
Dim request As WebRequest = WebRequest.Create(url)
Using response As WebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Using reader As New StreamReader(response.GetResponseStream(), Encoding.UTF8)
Dim dsResult As New DataSet()
dsResult.ReadXml(reader)
lblOriginAddress.Text = dsResult.Tables("DistanceMatrixResponse").Rows(0)("origin_address").ToString()
lblDestinationAddress.Text = dsResult.Tables("DistanceMatrixResponse").Rows(0)("destination_address").ToString()
lblDurationText.Text = dsResult.Tables("duration").Rows(0)("text").ToString()
lblDurationValue.Text = dsResult.Tables("duration").Rows(0)("value").ToString()
lblDistanceText.Text = dsResult.Tables("distance").Rows(0)("text").ToString()
lblDistanceValue.Text = dsResult.Tables("distance").Rows(0)("value").ToString()
End Using
End Using
End Sub
OutPut
Origin Address: |
Highcombe Cl, London SE9 4QH, UK |
Destination Address: |
Chislehurst BR7 5QP, UK |
Duration Text: |
8 mins |
Duration Value: |
493 |
Distance Text: |
3.3 km |
Distance Value: |
3290 |