Package geocode is an auto-generated package for the Geocoding API.
Convert addresses into geographic coordinates (geocoding), which you can use to place markers or position the map. This API also allows you to convert geographic coordinates into an address (reverse geocoding).
General documentation
For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on this page includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
// go get cloud.google.com/go/maps/geocode/apiv4@latest ctx := context.Background() // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in: // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := geocode.NewDestinationClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client, mentioned above.
req := &geocodepb.SearchDestinationsRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/cloud.google.com/go/maps/geocode/apiv4/geocodepb#SearchDestinationsRequest. } resp, err := c.SearchDestinations(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Use of Context
The ctx passed to NewDestinationClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Functions
func DefaultAuthScopes
func DefaultAuthScopes() []stringDefaultAuthScopes reports the default set of authentication scopes to use with this package.
CallOptions
type CallOptions struct {
GeocodeAddress []gax.CallOption
GeocodeLocation []gax.CallOption
GeocodePlace []gax.CallOption
}CallOptions contains the retry settings for each method of Client.
Client
type Client struct {
// The call options for this service.
CallOptions *CallOptions
// contains filtered or unexported fields
}Client is a client for interacting with Geocoding API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
A service for performing geocoding.
func NewClient
NewClient creates a new geocode service client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
A service for performing geocoding.
Example
package main
import (
"context"
geocode "cloud.google.com/go/maps/geocode/apiv4"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := geocode.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func NewRESTClient
NewRESTClient creates a new geocode service rest client.
A service for performing geocoding.
Example
package main
import (
"context"
geocode "cloud.google.com/go/maps/geocode/apiv4"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := geocode.NewRESTClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func (*Client) Close
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) Connection (deprecated)
func (c *Client) Connection() *grpc.ClientConnConnection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*Client) GeocodeAddress
func (c *Client) GeocodeAddress(ctx context.Context, req *geocodepb.GeocodeAddressRequest, opts ...gax.CallOption) (*geocodepb.GeocodeAddressResponse, error)GeocodeAddress this method performs an address geocode, which maps an address to a LatLng. It also provides structured information about the address.
Example
package main
import (
"context"
geocode "cloud.google.com/go/maps/geocode/apiv4"
geocodepb "cloud.google.com/go/maps/geocode/apiv4/geocodepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := geocode.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &geocodepb.GeocodeAddressRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/maps/geocode/apiv4/geocodepb#GeocodeAddressRequest.
}
resp, err := c.GeocodeAddress(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) GeocodeLocation
func (c *Client) GeocodeLocation(ctx context.Context, req *geocodepb.GeocodeLocationRequest, opts ...gax.CallOption) (*geocodepb.GeocodeLocationResponse, error)GeocodeLocation this method performs a location geocode, which maps a LatLng to an address. It also provides structured information about the address.
Example
package main
import (
"context"
geocode "cloud.google.com/go/maps/geocode/apiv4"
geocodepb "cloud.google.com/go/maps/geocode/apiv4/geocodepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := geocode.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &geocodepb.GeocodeLocationRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/maps/geocode/apiv4/geocodepb#GeocodeLocationRequest.
}
resp, err := c.GeocodeLocation(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) GeocodePlace
func (c *Client) GeocodePlace(ctx context.Context, req *geocodepb.GeocodePlaceRequest, opts ...gax.CallOption) (*geocodepb.GeocodeResult, error)GeocodePlace this method performs a geocode lookup using a place ID.
Example
package main
import (
"context"
geocode "cloud.google.com/go/maps/geocode/apiv4"
geocodepb "cloud.google.com/go/maps/geocode/apiv4/geocodepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := geocode.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &geocodepb.GeocodePlaceRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/maps/geocode/apiv4/geocodepb#GeocodePlaceRequest.
}
resp, err := c.GeocodePlace(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
DestinationCallOptions
type DestinationCallOptions struct {
SearchDestinations []gax.CallOption
}DestinationCallOptions contains the retry settings for each method of DestinationClient.
DestinationClient
type DestinationClient struct {
// The call options for this service.
CallOptions *DestinationCallOptions
// contains filtered or unexported fields
}DestinationClient is a client for interacting with Geocoding API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
A service for retrieving destinations.
A destination provides hierarchical context about a place, which allows you to, for example, find apartment buildings within a larger apartment complex and vice versa. It also provides navigation points suitable for use cases such as ridesharing or delivery.
func NewDestinationClient
func NewDestinationClient(ctx context.Context, opts ...option.ClientOption) (*DestinationClient, error)NewDestinationClient creates a new destination service client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
A service for retrieving destinations.
A destination provides hierarchical context about a place, which allows you to, for example, find apartment buildings within a larger apartment complex and vice versa. It also provides navigation points suitable for use cases such as ridesharing or delivery.
Example
package main
import (
"context"
geocode "cloud.google.com/go/maps/geocode/apiv4"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := geocode.NewDestinationClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func NewDestinationRESTClient
func NewDestinationRESTClient(ctx context.Context, opts ...option.ClientOption) (*DestinationClient, error)NewDestinationRESTClient creates a new destination service rest client.
A service for retrieving destinations.
A destination provides hierarchical context about a place, which allows you to, for example, find apartment buildings within a larger apartment complex and vice versa. It also provides navigation points suitable for use cases such as ridesharing or delivery.
Example
package main
import (
"context"
geocode "cloud.google.com/go/maps/geocode/apiv4"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := geocode.NewDestinationRESTClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func (*DestinationClient) Close
func (c *DestinationClient) Close() errorClose closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*DestinationClient) Connection (deprecated)
func (c *DestinationClient) Connection() *grpc.ClientConnConnection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*DestinationClient) SearchDestinations
func (c *DestinationClient) SearchDestinations(ctx context.Context, req *geocodepb.SearchDestinationsRequest, opts ...gax.CallOption) (*geocodepb.SearchDestinationsResponse, error)SearchDestinations this method performs a destination lookup and returns a list of destinations.
Example
package main
import (
"context"
geocode "cloud.google.com/go/maps/geocode/apiv4"
geocodepb "cloud.google.com/go/maps/geocode/apiv4/geocodepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := geocode.NewDestinationClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &geocodepb.SearchDestinationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/maps/geocode/apiv4/geocodepb#SearchDestinationsRequest.
}
resp, err := c.SearchDestinations(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}