从邮政编码自动填写城市和州 [英] Auto fill City and State from Zip code

查看:108
本文介绍了从邮政编码自动填写城市和州的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Experts,



有什么方法可以用邮政编码自动填写城市和州吗?



我想用一些非常简单的东西。



我在google中看到了一些结果大多数他们是AJAX通话,我们不想这样做。



我会很感激教程/代码/推荐链接。



我也愿意接受建议



谢谢

Hello Experts,

Is there any way that I can auto fill City and State with Zip code ?

I wanted to use something really simple.

I have seen some results in google where most of them were with AJAX calls, which we don't want to do it.

I would appreciate tutorials/ code/ referral link.

I am also open to suggestions

Thanks

推荐答案

显然,您只需要一个按邮政编码的城镇数据库(但是如何在更改完成后更新它?)或使用一个或另一个Web服务(甚至是一个站点)来获取这些数据。例如:

http://www.webservicex.net/uszip.asmx [< a href =http://www.webservicex.net/uszip.asmxtarget =_ blanktitle =New Window> ^ ],

http://www.webservicex.net/uszip.asmx?WSDL [ ^ ]。



如你所见,这是常规Web站点和Web服务。由于你有WSDL,这不会是一个问题:

https:/ /msdn.microsoft.com/en-us/library/dd355316.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/d2s8y7bs%28VS.100%29.aspx [ ^ ],

http://www.sitepoint.com/net-web-services-5-steps [ ^ ]。



并非所有服务都是这样的。在这种情况下,请阅读他们的API文档。您可以使用类 HttpWebRequest 处理低级别的任何Web资源。



参见: http://stackoverflow.com/questions/13407156/how -to-consume-a-webservice-using-wsdl-files-in-c-sharp [ ^ ]。



< dd> -SA
Apparently, you just need a database of cities/towns by zip codes (but how can you update it when changes are done?) or use one or another Web service (or even a site) to fetch this data. For example:
http://www.webservicex.net/uszip.asmx[^],
http://www.webservicex.net/uszip.asmx?WSDL[^].

As you can see, this is both a "regular" Web site, and a Web service. As you have WSDL, this won't be a problem:
https://msdn.microsoft.com/en-us/library/dd355316.aspx[^],
https://msdn.microsoft.com/en-us/library/d2s8y7bs%28VS.100%29.aspx[^],
http://www.sitepoint.com/net-web-services-5-steps[^].

Not all services work like that. In such cases, read their API documentation. You can work with any Web resource on low level using the class HttpWebRequest.

See also: http://stackoverflow.com/questions/13407156/how-to-consume-a-webservice-using-wsdl-files-in-c-sharp[^].

—SA


所以这是我的解决方案...



So here is my solution...

Dim ds As New DataSet()
       Dim url As String = "http://maps.google.com/maps/api/geocode/xml?address=" + txtZip.Text + "&sensor=false"
       Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(url)
       Using response As System.Net.WebResponse = DirectCast(request.GetResponse(), System.Net.HttpWebResponse)
           Using reader As New System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8)
               ds.ReadXml(reader)
               Dim dt As DataTable = ds.Tables("result")
               Dim strspliaddress = dt.Rows(0)("formatted_Address").ToString().Split(",")
               txtcity.Text = strspliaddress(0)
txtState.Text= strspliaddress(1)'Something like this


这篇关于从邮政编码自动填写城市和州的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆