我正在寻找一个好的工具,可以采用完整的邮件地址,格式化显示或与邮件标签一起使用,并将其转换为结构化对象.
例如:
// Start with a formatted address in a single string string f = "18698 E. Main Street\r\nBig Town, AZ, 86011"; // Parse into address Address addr = new Address(f); addr.Street; // 18698 E. Main Street addr.Locality; // Big Town addr.Region; // AZ addr.PostalCode; // 86011
现在我可以使用RegEx来做到这一点.但棘手的部分是保持它足够通用,以处理世界上的任何地址!
我确信必须有一些可以做到的东西.
如果有人注意到,这实际上是opensocial.address对象的格式.
Googlemaps API非常适用于此.例如,假设您被给予字符串"120 w 45 st nyc".将其传递到Googlemaps API,如下所示:http://maps.google.com/maps/geo?q=120+w+45+st+nyc
您会得到以下回复:
{ "name": "120 w 45 st nyc", "Status": { "code": 200, "request": "geocode" }, "Placemark": [ { "id": "p1", "address": "120 W 45th St, New York, NY 10036, USA", "AddressDetails": {"Country": {"CountryNameCode": "US","CountryName": "USA","AdministrativeArea": {"AdministrativeAreaName": "NY","Locality": {"LocalityName": "New York","Thoroughfare":{"ThoroughfareName": "120 W 45th St"},"PostalCode": {"PostalCodeNumber": "10036"}}}},"Accuracy": 8}, "ExtendedData": { "LatLonBox": { "north": 40.7603883, "south": 40.7540931, "east": -73.9807141, "west": -73.9870093 } }, "Point": { "coordinates": [ -73.9838617, 40.7572407, 0 ] } } ] }
如果您正在寻找一个简单解决方案的地址解析器,请尝试以下方法:
http://usaddress.codeplex.com/
好:1.无需数据库2.无需互联网查询3.非常准确
错误:1.无法确认它是否是真实地址2.仅适用于美国地址3.在C#中,使用.NET 3.5或更高版本