Skip to main content

Posts

Showing posts from November, 2014

Parsing mailing address in Java

Recently came across a problem to parse postal address String using Java, did some research here are some findings. Given String s = "60 Strawberry Hill Ave Stamford CT 06901" Required Result Street = Strawberry Hill Ave City = Stamford Number = 60 zip = 06901 state = CT You can use  JGeocoder public static void main(String[] args) { Map<AddressComponent, String> parsedAddr  =     AddressParser.parseAddress("Google Inc, 1600 Amphitheatre Parkway, Mountain View, CA 94043"); System.out.println(parsedAddr);       Map<AddressComponent, String> normalizedAddr  = AddressStandardizer.normalizeParsedAddress(parsedAddr);         System.out.println(normalizedAddr); } Output will be: {street=Amphitheatre, city=Mountain View, number=1600, zip=94043, state=CA, name=Google Inc, type=Parkway} {street=AMPHITHEATRE, city=MOUNTAIN VIEW, number=1600, zip=94043, state=CA, name=GOOGLE INC, type=PKWY} There is another library  International Address Par