geocoder

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2021 License: MIT Imports: 12 Imported by: 0

README

geocoder

A simple package provides Google Reverse Geocoding using Google Business Key

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressComponent

type AddressComponent struct {
	LongName  string   `json:"long_name"`
	ShortName string   `json:"short_name"`
	Types     []string `json:"types"`
}

type Bounds

type Bounds struct {
	SouthWest Coordinate `json:"southwest"`
	NorthEast Coordinate `json:"northeast"`
}

type BusinessKey

type BusinessKey struct {
	ClientID   string
	SigningKey string
	Channel    string
}

type Coordinate

type Coordinate struct {
	Lat float64 `json:"lat"`
	Lng float64 `json:"lng"`
}

type Geocoder

type Geocoder struct {
	// contains filtered or unexported fields
}

func NewGeocoder

func NewGeocoder(bkey *BusinessKey, baseURL, language string, client HttpRequester,
	requestPerSecond int, overQuerySleepDuration time.Duration, observer RequestObserver) (*Geocoder, error)

NewGeocoder creates new instance of Geocoder

func (*Geocoder) ReverseGeocode

func (g *Geocoder) ReverseGeocode(ctx context.Context, lat, lng float64) (*GoogleResponse, error)

ReverseGeocode makes reverse geocoding against latitude, longitude and returns GoogleResponse. The number of requests per second is respected

type Geometry

type Geometry struct {
	Location     Coordinate `json:"location"`
	LocationType string     `json:"location_type"`
}

type GoogleResponse

type GoogleResponse struct {
	Results []*ResultSet         `json:"results"`
	Status  GoogleResponseStatus `json:"status"`
}

type GoogleResponseStatus

type GoogleResponseStatus string
const (
	GRS_ZERO_RESULTS     GoogleResponseStatus = "ZERO_RESULTS"
	GRS_REQUEST_DENIED   GoogleResponseStatus = "REQUEST_DENIED"
	GRS_INVALID_REQUEST  GoogleResponseStatus = "INVALID_REQUEST"
	GRS_UNKNOWN_ERROR    GoogleResponseStatus = "UNKNOWN_ERROR"
	GRS_OVER_QUERY_LIMIT GoogleResponseStatus = "OVER_QUERY_LIMIT"
	GRS_OK               GoogleResponseStatus = "OK"
)

type HttpRequester added in v0.0.4

type HttpRequester interface {
	Get(targetURL string) (*http.Response, error)
}

type RequestObserver added in v0.0.3

type RequestObserver interface {
	ObserveHTTPRequest(label string, duration time.Duration)
}

type ResultSet

type ResultSet struct {
	AddressComponents []AddressComponent `json:"address_components"`
	FormattedAddress  string             `json:"formatted_address"`
	Geometry          Geometry           `json:"geometry"`
	PlaceID           string             `json:"place_id"`
	Types             []string           `json:"types"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL