Find out search location using VB.NET

Here I am going to discuss a simple application to find your search location in the google map using VB.NET.
  • 5484
 

Here I am going to discuss a simple application to find your search location in the google map, by street, city, state, zip code wise. You can also search your location by Latitude and Longitude.

<%
@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
    <
title>Untitled Page</title>
</
head>
<
body>
    <
form id="form1" runat="server">
        <
div>
            <
table width="300px" cellpadding="2" cellspacing="2" style="border1px solid maroon;">
                <
tr>
                    <
td colspan="2">
                        
&nbsp;<b>Search by Street, City, State and ZipCode</b
>
                    </td>
                </tr>
                <tr>
                    <td>
                        Street
                    </td>
                    <td>
                        <asp:TextBox ID="txtStreet" runat="server"></asp:TextBox>
                    
</td>
                
</tr>
                
<tr>
                    
<td>
                        
City
                    </td>
                    
<td>
                        
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
                    
</td>
                
</tr>
                
<tr>
                    
<td>
                        
State
                    </td>
                    
<td>
                        
<asp:TextBox ID="txtState" runat="server"></asp:TextBox>
                    
</td>
                
</tr>
                
<tr>
                    
<td>
                        
ZipCode
                    </td>
                    
<td>
                        
<asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox>
                    
</td>
                
</tr>
                
<tr>
                    
<td>
                    
</td>
                    
<td>
                        
<asp:Button ID="ButtonSearch" runat="server" Text="Search"OnClick="ButtonSearch_Click" /><br />
                    
</td>
                
</tr>
            
</table>
        
<div>&nbsp;
        </div>
            
<table width="300px" cellpadding="2" cellspacing="2" style="border1px solid maroon;">
                
<tr>
                    
<td colspan="2">
                        
&nbsp;<b>Search by Latitude and Longitude</b>
                    
</td>
                
</tr>
                
<tr>
                    
<td>
                        
Latitude</td>
                    
<td>
                        
<asp:TextBox ID="txtLat" runat="server"></asp:TextBox>
                    
</td>
                
</tr>
                
<tr>
                    
<td>
                        
Longitude</td>
                    
<td>
                        
<asp:TextBox ID="txtLong" runat="server"></asp:TextBox>
                    
</td>
                
</tr>
                
<tr>
                    
<td>
                    
</td>
                    
<td>
                        
<asp:Button ID="ButtonLatLong" runat="server" Text="Search by Lat Long"OnClick="ButtonLatLong_Click" CausesValidation="false" />
                    
</td>
                
</tr>
            
</table>
        
</div>
    
</form>
</
body>
</
html>

Add reference as follows:

Add.jpg

Figure 1:

addreference.jpg

Figure 2:

Imports
 System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms

Partial
 Public Class _Default 
    Inherits System.Web.UI.Page 
    Private url As String 

    
Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) 
    End Sub 

    Protected Sub ButtonSearch_Click(ByVal sender As ObjectByVal e As EventArgs) 
        Try 
            Dim street As String = String.Empty 
            Dim city As String = String.Empty 
            Dim state As String = String.Empty 
            Dim zip As String = String.Empty 

            
Dim queryAddress As New StringBuilder() 
            queryAddress.Append("http://maps.google.com/maps?q=") 

            If txtStreet.Text <> String.Empty Then 
                street = txtStreet.Text.Replace(" "c"+"c) 
                queryAddress.Append(street + ","c + "+"c) 
            End If 

            If txtCity.Text <> String.Empty Then 
                city = txtCity.Text.Replace(" "c"+"c) 
                queryAddress.Append(city + ","c + "+"c) 
            End If 

            If txtState.Text <> String.Empty Then 
                state = txtState.Text.Replace(" "c"+"c) 
                queryAddress.Append(state + ","c + "+"c) 
            End If 

            If txtZipCode.Text <> String.Empty Then 
                zip = txtZipCode.Text.ToString() 
                queryAddress.Append(zip) 
            End If 

            url = queryAddress.ToString() 
            Response.Redirect(url, False) 
        Catch ex As Exception 
            MessageBox.Show(ex.Message.ToString(), "Unable to Retrieve Map") 
        End Try 

    End Sub 

    Protected Sub ButtonLatLong_Click(ByVal sender As ObjectByVal e As EventArgs) 
        If txtLat.Text = String.Empty OrElse txtLong.Text = String.Empty Then 
            MessageBox.Show("Supply a latitude and longitude value""Missing Data") 
            Exit Sub 
        End If 

        Try
 
            Dim lat As String = String.Empty 
            Dim lon As String = String.Empty 

            Dim queryAddress As New StringBuilder() 
            queryAddress.Append("http://maps.google.com/maps?q=") 

            If txtLat.Text <> String.Empty Then 
                lat = txtLat.Text 
                queryAddress.Append(lat & "%2C") 
            End If 

            If txtLong.Text <> String.Empty Then 
                lon = txtLong.Text 
                queryAddress.Append(lon) 
            End If 

            url = queryAddress.ToString() 
            Response.Redirect(url, False) 
        Catch ex As Exception 
            MessageBox.Show(ex.Message.ToString(), "Error") 
        End Try 
    End Sub 
End
 Class 

Output:

Search.jpg

Figure 3:
 

Suppose you want to search Radisson hotel in Noida, India as follows:

Search2.jpg

Figure 4:

You will get the following search result with map.

result.jpg

Figure 5:

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.