Click here to Skip to main content
15,867,453 members
Articles / Web Development / ASP.NET
Article

Address Book that shows the physical address

Rate me:
Please Sign up or sign in to vote.
1.74/5 (8 votes)
3 Oct 20042 min read 49.6K   25   5
This article shows how you can use MapQuest QueryString in your own application.

Introduction

Have you ever made an address book? What does it have? Addresses, names, emails, and maybe you can also send an email using your address book, right? How cool it would be if you have a list of people in your table with their addresses and when you click on a person's information you can see his physical address. In this article I will show you how easy it is to attach the parameters to the request sent to MapQuest. You can use any type of address finder website you wish to use, I will be using MapQuest in my example.

Making the database

Let's first make a simple database which contains Person ID, Name, and ZIP code. You can use the full address of a person but I have noticed that most of the time services like MapQuest are not able to locate the actual address. I will be using ZIP code for finding the address. Enter some data in the database and we are ready to go!

Displaying Data on the Page

Let's display data on the page by using a DataGrid. All the addresses and ZIP codes you see below are added in your Address Book. Let's assume that your ZIP code is 77304. So we will be finding directions from your ZIP code to the ZIP codes in your address book. Here is how it will look like when you display the DataGrid on the page.

Sample screenshot

Redirecting to MapQuest

I thought about this and could not find a better way to redirect to the directions page. There are several ways that you can perform it like opening the directions page in the new pop up window, or maybe in the frame. I chose a new page (not a pop up) because some browsers have pop up killers so on those browsers the pop up will not open, or in other words the pop up will be killed. Frames also had some problems since some browsers do not support frames. Keeping these reasons in front of me, I chose redirecting the same page to the directions page.

Implementing DataGrid Select Column Code

Time has come to code, so, in the DataGrid's SelectedIndexChanged event, write this code:

C#
private void ChangeSelection(object sender, System.EventArgs e)
{
    // gets the selected ZipCode from the DataGrid selected row
    string otherZipCode = myDataGrid.SelectedItem.Cells[2].Text;

    // This is the URL in which we are going to embed our parameters.
    string url = "http://www.mapquest.com/directions/main.adp?" + 
                 "go=1&do=nw&un=m&2tabval=address&cl=EN" + 
                 "&ct=NA&1tabval=address&1y=US&" + 
                 "1a=&1c=&1s=&1z="+myZipCode+ 
                 "&1ah=&2y=US&2a=&2c=&2s=&2z="+
                 otherZipCode + "&2ah=&idx=0&" + 
                 "id=4160c6ba-001df-01660-cdbcf364&" + 
                 "aid=4160c6ba-001e0-01660-cdbcf364"; 

    // Redirec to the other page
    Response.Redirect(url); 

}

Yeah, that's all you have to do. I just embedded the variables that contained the values of myZipCode and otherZipCode in the URL, pretty simple right!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
My name is Mohammad Azam and I have been developing iOS applications since 2010. I have worked as a lead mobile developer for VALIC, AIG, Schlumberger, Baker Hughes, Blinds.com and The Home Depot. I have also published tons of my own apps to the App Store and even got featured by Apple for my app, Vegetable Tree. I highly recommend that you check out my portfolio. At present I am working as a lead instructor at DigitalCrafts.




I also have a lot of Udemy courses which you can check out at the following link:
Mohammad Azam Udemy Courses

Comments and Discussions

 
GeneralSee also Pin
Steven Campbell4-Oct-04 1:23
Steven Campbell4-Oct-04 1:23 
GeneralRe: See also Pin
Anonymous5-Oct-04 8:16
Anonymous5-Oct-04 8:16 
QuestionWhat about addresses outside the US? Pin
Jos Branders3-Oct-04 22:58
Jos Branders3-Oct-04 22:58 
AnswerRe: What about addresses outside the US? Pin
azamsharp4-Oct-04 3:07
azamsharp4-Oct-04 3:07 
GeneralFormatting of the Article Pin
azamsharp3-Oct-04 19:32
azamsharp3-Oct-04 19:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.