3

I need to display the location and city name when a user enters a ZIP Code. How do I get the corresponding location names?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
karthik k
  • 3,751
  • 15
  • 54
  • 68

6 Answers6

3

I would use a website like

http://www.zipinfo.com/search/zipcode.htm

and just send the zipcode to that, retrieve the input, parse for the city name, easy as that.

Austin
  • 4,801
  • 6
  • 34
  • 54
  • thanks for the reply. In which format i will get the output from the site?. – karthik k Jun 01 '11 at 05:47
  • I don't understand what you mean by what format. Just a standard format from the website. – Austin Jun 01 '11 at 05:58
  • I mean i am developing an .net application, in that user enters zip code, so i need to display the corresponding city name. I will pass the zip code to the above given url. then i need to read the output from the site, for this I asked you in whethar the site send the response in a xml format or any other file? – karthik k Jun 01 '11 at 06:02
  • No, no file. Just responds with simple HTML. Just as easy to parse as if it gave you a file, maybe even easier. – Austin Jun 01 '11 at 06:04
  • @karthik k: you should use the HtmlAgilityPack for this. read this http://stackoverflow.com/questions/3978428/parse-a-html-combox-in-c for getting more information. – Doc Brown Jun 01 '11 at 06:33
  • THis url is working only 30 trials per day. BUt I want to use it for everyday without limit trials. Do you know any other websites – karthik k Jun 03 '11 at 09:01
  • @karthikk -- see my answer below for something possibly more acceptable. – Matt Jan 23 '12 at 20:00
3

Try the USPS zipcode API - http://www.usps.com/webtools/welcome.htm

tofutim
  • 22,664
  • 20
  • 87
  • 148
1

You can use the PlaceFinder geocoding web service to make REST based requests using the postal code you want to resolve to a name. The service supports both XML and JSON response formats. Here is a listing of the response elements returned by the service.

Using .NET, you would leverage the client or request/response classes in the System.Net namespace to make a request to the service and process the reponse.

Oppositional
  • 11,141
  • 6
  • 50
  • 63
0

The simplest way would be to use strings. You could alternatively create a ZIP class, if you wanted to get fancy.

using System;
using System.Collections.Generic;

class Program
{
    // declare your variable
    private static Dictionary<string, string> zipLookup;

    public static void CreateZips()
    {
        zipLookup = new Dictionary<string, string>();
        zipLookup.Add("90210", "Beverly Hills");
        // fill all other values, probably from a db
    }

    static void Main(string[] args)
    {
        CreateZips();

        var test  = "90210";

        if (zipLookup.ContainsKey(test))
        {
            Console.WriteLine(test.ToString() + "=" + zipLookup[test]);
        }
        else
        {
            Console.WriteLine(test.ToString() + " location unknown");
        }
    }
}

For more details on ZIPs, check out Wikipedia

Gustavo Mori
  • 8,319
  • 3
  • 38
  • 52
  • zipLookup.Add(new KeyValuePair(90210, "Beverly Hills"); -- here you have given the city name, how come we know that the city name for the particular zip code? – karthik k Jun 01 '11 at 05:53
  • @karthik k you need to have a lookup. Perhaps you have DB or you look it up online at runtime. The values don't come from thin air, you need to populate them somehow :) – Gustavo Mori Jun 01 '11 at 06:04
0

Alternatively, you can use https://thezipcodes.com/

This has almost all the data that I used for the search. Use http://thezipcodes.com/docs to use the API.

nkkumawat
  • 693
  • 1
  • 6
  • 9
0

I work in the address verification industry for a company called SmartyStreets. The solutions presented here are all functional in a variety of ways, but beware of their limitations and specialties. For example, Yahoo's service is more like address suggestion, not validation. The USPS web service is quite limited in the results it returns, for example: you won't get the County and Component data of an address, actual deliverability, etc.

For a more flexible, free solution -- may I suggest our LiveAddress API? It's a REST-ful endpoint which, given a street address (for example) and ZIP code, will fully and accurately complete the entire address.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Matt
  • 22,721
  • 17
  • 71
  • 112