如何匹配网站上的地址? (正则表达式?图书馆?谷歌地图?)
我想匹配/突出显示地址例如(253 West 125th Street New York, NY 10027)
通过 JavaScript 在网站上。
问题:
- 如何匹配内容中的地址? (对于尽可能多的国家 可能)
- 您知道有哪些图书馆或课程可以提供想法吗?
- 什么正则表达式系统可以工作(包含字母、数字,并且有 3 到 15 个单词)?
- 我们是否应该将其与 Google API 进行匹配以了解它是否是有效地址?
感谢您的任何想法和意见! :)
I would like to match/highlight addresses e.g. (253 West 125th Street
on websites via javascript.
New York, NY 10027)
Questions:
- How to match addresses in content? (for as many countries as
possible) - Do you know any library or class to get an idea?
- What regex system could work (contains letters, numbers and has between 3 and 15 words)?
- Should we match it against the Google API to get an idea if it's a valid address?
thank you for any ideas and input! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
雅虎!有一个位置 API,可以将地址映射到地理位置。对于 Yahoo! 提供的完整地理服务!访问以下地址。
http://developer.yahoo.com/geo/
雅虎! PlaceFinder™ 将街道地址和地名转换为地理坐标。
Yahoo! has a location API which can map addresses to geo locations. For complete geographical services provided by Yahoo! visit the below address.
http://developer.yahoo.com/geo/
Yahoo! PlaceFinder™ converts street addresses and place names into geographic coordinates.
谷歌地图、必应!诺基亚地图(之前的 Navteq 和诺基亚 Ovi 地图,现在集成到 Bing 的诺基亚地图!)也提供了地理编码 API,您可以使用它们将地址转换为真实的地理位置。
Google 地图 API:http://code.google.com/apis/maps /documentation/javascript/services.html
干杯!!!
Google Maps, Bing! and Nokia Maps (earlier Navteq and Nokia Ovi Maps, now Nokia Maps integrated to Bing!) also provides geocoding APIs which you can use to convert the addresses to real geo locations.
Google Maps API : http://code.google.com/apis/maps/documentation/javascript/services.html
Cheers!!!
哎哟!这是一个棘手的问题。不幸的是,世界上没有正则表达式可以拯救你。唯一真正的方法是使用某种地址验证服务。是的,谷歌地图和各种替代方案通常可以告诉您某个地址是否看起来真实,甚至可能将其绘制在地图上,但它们无法告诉您该地址是否确实真实以及是否可以接收邮件等。
我想所有这一切中更大的业务(而不是技术)问题是:你为什么要首先收集地址?如果您正在收集一条数据,知道它是正确的不是很好吗?例如,您不想知道信用卡是否真的有效,而不是收集信用卡号并假设它可能是正确的,因为它通过了 mod 10 校验和。或者电话号码或电子邮件怎么样?当然,它可能会通过正则表达式,但除非电话/电子邮件附加到一个人,否则它有什么用呢?
地址也是如此。 可能真实的地址与通过完整性检查但不是发行的信用卡号码的信用卡号码一样糟糕。确保地址可送达的唯一方法是利用第三方地址验证网络服务。
有许多提供商提供可以通过 Javascript 连接的 Web 服务。为了充分披露,我是 SmartyStreets 的创始人。我们提供基于 REST 的地址验证 Web 服务,称为 LiveAddress,可以通过 Javascript 访问。它甚至可以接受 JSONP 调用来绕过跨域请求。
Ouch! This is a tough problem. Unfortunately there isn't a regex in the world that can save you. The only real way to do this is by using some kind of address verification service. Yes Google Maps and the various alternatives can generally tell you if an address looks real and perhaps even plot it on a map, but they can't tell you whether or not the address is actually real and can, for example, receive mail.
I guess the bigger business (rather than technical) question in all of this is: why are you collecting the address in the first place? If you're collecting a piece of data wouldn't it be nice to know that it's correct? For example, rather than collecting a credit card number and assuming that it might be correct because it passes a mod 10 checksum, wouldn't you like to know if the credit card is actually good? Or how about a phone number or email? Sure it might pass a regex, but unless the phone/email is attached to a person, then what good does it do?
The same thing goes with addresses. An address that might be real is just as bad as credit card number that passes integrity checks but isn't an issued credit card number. The only way to ensure an address is deliverable is to utilize a 3rd-party address verification web service.
There are a number of providers out there that offer web services that can be interfaced via Javascript. In the interest of full disclosure, I'm the founder of SmartyStreets. We offer a REST-based address verification web service called LiveAddress that can be accessed through Javascript. It can even accept JSONP calls to get around cross-domain requests.