Skip to content

Commit

Permalink
Fixing formattedAddress field name
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvins committed May 7, 2017
1 parent e43b5a2 commit 1930394
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func main() {
// fmt.Println(geocoder.FormatAddress(address))
//}
fmt.Println(geocoder.FormatAddress(addresses[0]))
fmt.Println(addresses[0].FormatedAddress)
fmt.Println(addresses[0].FormattedAddress)
fmt.Println(addresses[0].Types)
}
}
Expand Down
43 changes: 23 additions & 20 deletions geocoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ func init() {
}

// Address structure used in the Geocoding and GeocodingReverse functions
// Note: The FormattedAddress field should be used only for the GeocodingReverse
// to get the formatted address from the Google Geocoding API. It is not used in
// the Geocoding function.
type Address struct {
Street string
Number int
District string
City string
County string
State string
Country string
PostalCode string
FormatedAddress string
Types string
Street string
Number int
District string
City string
County string
State string
Country string
PostalCode string
FormattedAddress string
Types string
}

// Location structure used in the Geocoding and GeocodingReverse functions
Expand All @@ -58,20 +61,20 @@ func FormatAddress(address Address) string {
content = append(content, address.State)
content = append(content, address.Country)

var formatedAddress string
var formattedAddress string

// For each value in the content slice check if it is valid
// and add to the formatedAddress string
// and add to the formattedAddress string
for _, value := range content {
if value != "" {
if formatedAddress != "" {
formatedAddress += ", "
if formattedAddress != "" {
formattedAddress += ", "
}
formatedAddress += value
formattedAddress += value
}
}

return formatedAddress
return formattedAddress
}

// httpRequest function send the HTTP request, decode the JSON
Expand Down Expand Up @@ -129,11 +132,11 @@ func Geocoding(address Address) (Location, error) {
var location Location

// Convert whitespaces to +
formatedAddress := FormatAddress(address)
formatedAddress = strings.Replace(formatedAddress, " ", "+", -1)
formattedAddress := FormatAddress(address)
formattedAddress = strings.Replace(formattedAddress, " ", "+", -1)

// Create the URL based on the formated address
url := geocodeApiUrl + "address=" + formatedAddress
url := geocodeApiUrl + "address=" + formattedAddress

// Use the API Key if it was set
if ApiKey != "" {
Expand Down Expand Up @@ -201,7 +204,7 @@ func convertResultsToAddress(results structs.Results) (addresses []Address) {
}
}

address.FormatedAddress = results.Results[index].FormattedAddress
address.FormattedAddress = results.Results[index].FormattedAddress
address.Types = results.Results[index].Types[0]

addresses = append(addresses, address)
Expand Down
10 changes: 5 additions & 5 deletions geocoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestFormatAddress(t *testing.T) {
// Table tests
var tTests = []struct {
address Address
formatedAddress string
formattedAddress string
}{
{address1, ""},
{address2, "123, Cork Street, Cork, Ireland"},
Expand All @@ -45,11 +45,11 @@ func TestFormatAddress(t *testing.T) {

// Test with all values from the tTests
for _, pair := range tTests {
formatedAddress := FormatAddress(pair.address)
formattedAddress := FormatAddress(pair.address)

if formatedAddress != pair.formatedAddress {
t.Error("Expected:", pair.formatedAddress,
"Received:", formatedAddress)
if formattedAddress != pair.formattedAddress {
t.Error("Expected:", pair.formattedAddress,
"Received:", formattedAddress)
}
}
}
Expand Down

0 comments on commit 1930394

Please sign in to comment.