Geocode an address with Thinwrap (Go)
Resolve an address to coordinates via the Thinwrap Geocoding facade in Go — one call shape for Mapbox, Google, HERE and more.
1. Install
go get github.com/thinwrap/location-go2. Send the call
import "github.com/thinwrap/location-go"
g := location.NewGeocoding(location.GoogleConfig{
APIKey: os.Getenv("GOOGLE_MAPS_API_KEY"),
})
res, err := g.Geocode(ctx, location.GeocodeOptions{
Address: "1600 Amphitheatre Parkway, Mountain View, CA",
CountryFilter: []string{"US"},
})
if err != nil {
var ce *location.ConnectorError
if errors.As(err, &ce) {
log.Printf("%s: %s", ce.ProviderCode, ce.ProviderMessage)
}
return
}
for _, c := range res.Candidates {
fmt.Println(c.FormattedAddress, c.Location.Lat, c.Location.Lng)
}
Same code works for all supported providers — just change the provider ID.