How to Normalize an Address in Go

Cloudmersive
1 min readJun 18, 2021

Manually parsing user addresses for input into programs or data-tracking tools can be an aggravating task. To simplify the process, you can use the following API in Go to normalize and validate input street addresses, with the added benefit of retrieving latitude and longitude coordinates as well.

To perform the operation, add your input parse request into the below example code:

package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/validate/address/street-address/normalize"
method := "POST"
payload := strings.NewReader(`{
"StreetAddress": "<string>",
"City": "<string>",
"StateOrProvince": "<string>",
"PostalCode": "<string>",
"CountryFullName": "<string>",
"CountryCode": "<string>"
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

In seconds, you will have the individual components of the address, the validity result; if the valid result was positive, you will also receive the latitude and longitude coordinates.

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.