ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Calculate Distance, Duration between two locations in Google Maps API using C# and VB.Net in ASP.Net<blockquote><cite>nauna says:</cite> <pre><code class="csharp spaces"></code><code class="csharp plain">distance.Text = dsResult.Tables[</code><code class="csharp string">"duration"</code><code class="csharp plain">].Rows[0][</code><code class="csharp string">"value"</code><code class="csharp plain">].ToString() + dsResult.Tables[</code><code class="csharp string">"distance"</code><code class="csharp plain">].Rows[0][</code><code class="csharp string">"text"</code><code class="csharp plain">].ToString();</code></pre> </blockquote> <p>Replace the above line with below.</p> <pre class="brush: csharp">distance.Text = dsResult.Tables[&#34;distance&#34;].Rows[0][&#34;text&#34;].ToString();</pre> <p>Check the below sample code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;div&gt; duration; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;duration&#34; /&gt; Distance: &lt;asp:TextBox ID=&#34;distance&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Namespaces</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Net; using System.IO; using System.Text; using System.Data;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Net Imports System.IO Imports System.Data</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">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 + "&amp;destinations=" + destination + "&amp;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[&#34;distance&#34;].Rows[0][&#34;text&#34;].ToString(); } } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load Dim origin As String = &#34;Oberoi Mall, Goregaon&#34; Dim destination As String = &#34;Infinity IT Park, Malad East&#34; Dim url As String = &#34;https://maps.googleapis.com/maps/api/distancematrix/xml?origins=&#34; &amp; origin &amp; &#34;&amp;destinations=&#34; &amp; destination &amp; &#34;&amp;key=AIzaSyBE1J5Pe_GZXBR_x9TXOv6TU5vtCSmEPW4&#34; 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(&#34;duration&#34;).Rows(0)(&#34;text&#34;).ToString() distance.Text = dsResult.Tables(&#34;distance&#34;).Rows(0)(&#34;text&#34;).ToString() End Using End Using End Sub</pre>https://www.aspforums.net:443/Threads/515185/Calculate-Distance-Duration-between-two-locations-in-Google-Maps-API-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/515185/Calculate-Distance-Duration-between-two-locations-in-Google-Maps-API-using-C-and-VBNet-in-ASPNet/Thu, 06 Dec 2018 06:18:11 GMT