Friday 7 February 2014

How to Search a Place in Map using Google Map API in Asp.Net


Description:-


 In this example, i will explain that  how to search place, city in a map using Google map in ASP.NET.now days When you are see  all the website or any other web contacts address are attached with map of the city with it’s proper address in the Google map. the Google has been provided a incredible map service to find the any palce, address, zipcode, state,city through the external web application. So we will implement a web application like find the address with Google map in asp.net.

Here we simply use the following link to display your location in Google map like



and then we simply atteched the city and state location append to the above link like
StringBuilder queryAddress = new StringBuilder();
            queryAddress.Append("http://maps.google.com/maps?q=");

       

            if (txtCity.Text != string.Empty)
            {
                city = txtCity.Text.Replace(' ', '+');
                queryAddress.Append(city + ',' + '+');
            }

            if (txtState.Text != string.Empty)
            {
                state = txtState.Text.Replace(' ', '+');
                queryAddress.Append(state + ',' + '+');
            }

            if (txtZipCode.Text != string.Empty)
            {
                zip = txtZipCode.Text.ToString();
                queryAddress.Append(zip);
            }
            url = queryAddress.ToString();
            Response.Redirect(url, false);

And finally we will redirect the page to the url that we are created.

upload image in database using Image datatype upload image in database having datatype is image

extract or convert unzip files to zip folder extract unzip files to zip file in asp.net

bind Accordion panel with dynamic data bind ajax accordion panel with dynamic data




searchcityingooglemap.aspx:-



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="searchcityingooglemap.aspx.cs" Inherits="searchcityingooglemap" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table width="300px" cellpadding="2" cellspacing="2" style="border: 1px solid maroon;">
                <tr>
                    <td colspan="2">
                        &nbsp;<b>Search Your City Map By Adding  City, State and ZipCode FRom Google Map</b>
                    </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>
    </form>
</body>
</html>

 searchcityingooglemap.aspx.cs:-
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;
using System.Drawing;


public partial class searchcityingooglemap : System.Web.UI.Page
{

    string url;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ButtonSearch_Click(object sender, EventArgs e)
    {
        try
        {
       
            string city = string.Empty;
            string state = string.Empty;
            string zip = string.Empty;

            StringBuilder queryAddress = new StringBuilder();
            queryAddress.Append("http://maps.google.com/maps?q=");

       

            if (txtCity.Text != string.Empty)
            {
                city = txtCity.Text.Replace(' ', '+');
                queryAddress.Append(city + ',' + '+');
            }

            if (txtState.Text != string.Empty)
            {
                state = txtState.Text.Replace(' ', '+');
                queryAddress.Append(state + ',' + '+');
            }

            if (txtZipCode.Text != string.Empty)
            {
                zip = txtZipCode.Text.ToString();
                queryAddress.Append(zip);
            }
            url = queryAddress.ToString();
            Response.Redirect(url, false);
        }
        catch (Exception ex)
        {
           // MessageBox.Show(ex.Message.ToString(), "Unable to Retrieve Map");
        }
    }
}
 

0 comments:

Post a Comment