Normalize an Address in C/C++
Do you gather user address information from emails or forms? If so, parsing it into individual parts for organization and use can be an aggravating task. Throw in the fact that some addresses may be invalid, and you’ve got yourself a sizable headache. To simplify the process, you can use the following API in C/C++ to normalize, validate, and retrieve location coordinates for an input structured street address.
Let’s begin the operation by installing libcurl into your C/C++ project:
libcurl/7.75.0
Next, you can call the validation function by inputting your request into the following example code:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/validate/address/street-address/normalize");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: application/json");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\n \"StreetAddress\": \"<string>\",\n \"City\": \"<string>\",\n \"StateOrProvince\": \"<string>\",\n \"PostalCode\": \"<string>\",\n \"CountryFullName\": \"<string>\",\n \"CountryCode\": \"<string>\"\n}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
This will allow you to improve organization of address information and spend less time on manual processing.