通过提供邮政编码获得位置名称

问题描述 投票:2回答:5

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

c# rss weather zipcode
5个回答
3
投票

我会使用类似的网站

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

然后将邮政编码发送给它,检索输入,解析城市名称,就这么简单。


3
投票

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


1
投票

您可以使用PlaceFinder地理编码Web服务使用要解析为名称的邮政编码来制作REST based requests。该服务同时支持XML和JSON response formats。这是服务返回的response elements的列表。

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


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的更多详细信息,check out Wikipedia


0
投票

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

[更灵活,免费的解决方案-我可以建议我们使用US Street Address API吗?这是一个REST-ful端点,给定街道地址(例如)和邮政编码,它将完全准确地完成整个地址。

© www.soinside.com 2019 - 2024. All rights reserved.