3

当用户输入邮政编码时,我需要显示位置和城市名称。如何获取对应的位置名称?

4

6 回答 6

3

我会使用像这样的网站

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

只需将邮政编码发送到那里,检索输入,解析城市名称,就这么简单。

于 2011-06-01T05:40:39.767 回答
3

试试 USPS 邮政编码 API - http://www.usps.com/webtools/welcome.htm

于 2011-06-01T05:42:40.400 回答
1

您可以使用PlaceFinder地理编码 Web 服务,使用您想要解析为名称的邮政编码发出基于 REST 的请求。该服务支持 XML 和 JSON响应格式。这是服务返回的响应元素的列表。

使用 .NET,您将利用System.Net命名空间中的客户端或请求/响应类向服务发出请求并处理响应。

于 2011-06-01T06:18:47.550 回答
0

最简单的方法是使用字符串。如果您想花哨的话,您也可以创建一个 ZIP 类。

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");
        }
    }
}

有关 ZIP 的更多详细信息,请查看 Wikipedia

于 2011-06-01T05:48:55.363 回答
0

我在一家名为SmartyStreets的公司从事地址验证行业。这里介绍的解决方案都以多种方式发挥作用,但要注意它们的局限性和特殊性。例如,雅虎的服务更像是地址建议,而不是验证。USPS Web 服务返回的结果非常有限,例如:您不会获得地址的县和组件数据、实际可交付性等。

对于更灵活、免费的解决方案——我可以推荐我们的LiveAddress API吗?这是一个 REST-ful 端点,给定街道地址(例如)和邮政编码,将完整准确地完成整个地址。

于 2012-01-23T20:01:03.483 回答
0

或者,您可以使用https://thezipcodes.com/

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

于 2020-12-31T13:09:17.557 回答