Search code examples
street-addressazure-maps

Azure Maps SearchAddressResultItem.Address.FreeFormAddress is incomplete


I am using Azure Maps to get back a corrected address and its location. The FreeFormAddress is not great because:

  1. It does not include the country.
  2. It has just the 5 digit zip, not the 5+4.
  3. It is all one line so it does not display as people expect it.

Is there a way to get the address back where its complete with country, full zip code, etc. and with \n as appropriate so it's how one would put it on an envelope?

I can build a string that's correct for the U.S. from SearchAddressResultItem.Address. But I doubt it would be correct for say Vietnam.


Solution

  • Very rarely, if at all will the formatted address contain country. It will never contain zip 5+4. The search API's are designed to take addresses and find the coordinate for it. Any additional information returned is primarily to assist the user in verifying that the right result was returned and does not include regional mail formatted address strings. If you have a limited number of countries in which you plan to focus on, you can build a bit of logic that formats the structured address parts into the expect regional mailing address format. If you want to support more than a couple of countries, there are several open-source libraries that have pretty comprehensive coverage for mail address formatting. Here are some: