what3words

package module
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 11 Imported by: 1

README

API for What3words for Golang

This project is licensed under the terms of the MIT license.

It provides a simple Go wrapper for the What3words V3 API.

What3words GoDoc

Supports:

  • What3words API V3

Installation

Install:

go get -u github.com/jcmurray/what3words

Import:

import "github.com/jcmurray/what3words"

Quickstart

func ExampleConvertTo3wa() {
        api := what3words.NewGeocoder("[MK_API_KEY]")
        coords, err := what3words.NewCoordinates(51.520847, -0.195521)
        if err != nil {
                panic(err)
        }
        resp, err := api.ConvertTo3wa(coords)
        if err != nil {
                panic(err)
        }
        fmt.Printf("What3Names: %s\n", resp.Words)
        // Output: What3Names: filled.count.soap
}

func ExampleConvertToCoords() {
        api := what3words.NewGeocoder("[MK_API_KEY]")
        resp, err := api.ConvertToCoords("filled.count.soap")
        if err != nil {
            panic(err)
        }
        fmt.Printf("Coords - Lat: %.6f, Lon: %0.6f\n", resp.Coordinates.Latitude, resp.Coordinates.Longitude)}
        // Output: Coords - Lat: 51.520847, Lon: -0.195521
}

func ExampleAutoSuggest() {
        api := what3words.NewGeocoder("[MK_API_KEY]")
        autoreq := what3words.NewAutoSuggestRequest("plan.clips.a")
        coords, err := what3words.NewCoordinates(51.520847, -0.195521)
	autoreq.SetFocus(coords)

	resp, err := api.AutoSuggest(autoreq)
	if err != nil {
		fmt.Printf("Error: %s", err)
		return
	}
	fmt.Printf("======================\n")
	for _, suggestion := range resp.Suggestions {
		fmt.Printf("Country: %s\n", suggestion.Country)
		fmt.Printf("Nearest Place: %s\n", suggestion.NearestPlace)
		fmt.Printf("Words: %s\n", suggestion.Words)
		fmt.Printf("Distance to Focus km: %.3f\n", suggestion.DistanceToFocusKm)
		fmt.Printf("Rank: %d\n", suggestion.Rank)
		fmt.Printf("Language: %s\n", suggestion.Language)
		fmt.Printf("======================\n")
	}
        // Output:
        // ======================
        // Country: GB
        // Nearest Place: Brixton Hill, London
        // Words: plan.clips.area
        // Distance to Focus km: 11.000
        // Rank: 1
        // Language: en
        // ======================
        // Country: GB
        // Nearest Place: Borehamwood, Herts.
        // Words: plan.clips.arts
        // Distance to Focus km: 16.000
        // Rank: 2
        // Language: en
        // ======================
        // Country: GB
        // Nearest Place: Wood Green, London
        // Words: plan.slips.cage
        // Distance to Focus km: 13.000
        // Rank: 3
        // Language: en
        // ======================
}

func ExampleGridSelect() {
        api := what3words.NewGeocoder("[MK_API_KEY]")
        coord1, _ := w3w.NewCoordinates(52.207988, 0.116126)
	coord2, _ := w3w.NewCoordinates(52.208867, 0.117540)
	box, _ := w3w.NewBox(coord1, coord2)
	resp, err := api.GridSection(box)
	if err != nil {
		fmt.Printf("Error: %s", err)
		return
	}
	fmt.Printf("======================\n")
	for _, line := range resp.Lines {
		fmt.Printf("Line Start: %.13f, %.13f\n", line.Start.Latitude, line.Start.Longitude)
		fmt.Printf("Line End  : %.13f, %.13f\n", line.End.Latitude, line.End.Longitude)
		fmt.Printf("======================\n")
        }
        // Output:
        // ======================
        // Line Start: 52.2080099180681, 0.1161260000000
        // Line End  : 52.2080099180681, 0.1175400000000
        // ======================
        // Line Start: 52.2080368693402, 0.1161260000000
        // Line End  : 52.2080368693402, 0.1175400000000
        // ======================
        // Line Start: 52.2080638206123, 0.1161260000000
        // Line End  : 52.2080638206123, 0.1175400000000
        // ...
}

func ExampleAvailableLanguages() {
        api := what3words.NewGeocoder("[MK_API_KEY]")
	resp, err := api.AvailableLanguages()
	if err != nil {
		fmt.Printf("Error: %s", err)
		return
	}
	fmt.Printf("======================\n")
	for _, language := range resp.Languages {
		fmt.Printf("Name       : %s\n", language.Name)
		fmt.Printf("Code       : %s\n", language.Code)
		fmt.Printf("Native Name: %s\n", language.NativeName)
		fmt.Printf("======================\n")
	}
        // Output:
        // ======================
        // Name       : German
        // Code       : de
        // Native Name: Deutsch
        // ======================
        // Name       : Hindi
        // Code       : hi
        // Native Name: हिन्दी
        // ======================        
}

func ExampleConvertTo3waGeoJSON() {
        api := what3words.NewGeocoder("[MK_API_KEY]")
        coords, err := what3words.NewCoordinates(51.520847, -0.195521)
        if err != nil {
                panic(err)
        }
	resp, err := api.ConvertTo3waGeoJSON(coords)
	if err != nil {
		fmt.Printf("Error: %s", err)
		return
	}
	fmt.Printf("What3Names: %s\n", resp.Features[0].Properties["words"])
        // Output: What3Names: filled.count.soap
}

func ExampleConvertToCoordsGeoJSON() {
        api := what3words.NewGeocoder("[MK_API_KEY]")
	resp, err := api.ConvertToCoordsGeoJSON("filled.count.soap")
	if err != nil {
		fmt.Printf("Error: %s", err)
		return
	}
	coordsGeo := resp.Features[0].Geometry.Point
	fmt.Printf("Coords - Lat: %.6f, Lon: %0.6f\n", coordsGeo[1], coordsGeo[0])
	// Output: Coords - Lat: 51.520847, Lon: -0.195521
}

func ExampleGridSelectGeoJSON() {
        api := what3words.NewGeocoder("[MK_API_KEY]")
        coord1, _ := w3w.NewCoordinates(52.207988, 0.116126)
	coord2, _ := w3w.NewCoordinates(52.208867, 0.117540)
	box, _ := w3w.NewBox(coord1, coord2)
	respGeo, err := api.GridSectionGeoJSON(box)
	if err != nil {
		fmt.Printf("Error: %s", err)
		return
	}
	fmt.Printf("======================\n")
	for _, line := range respGeo.Features[0].Geometry.MultiLineString {
		fmt.Printf("Line Start: %.13f, %.13f\n", line[0][1], line[0][0])
		fmt.Printf("Line End  : %.13f, %.13f\n", line[1][1], line[1][0])
		fmt.Printf("======================\n")
	}
        // Output:
        // ======================
        // Line Start: 52.2080099180681, 0.1161260000000
        // Line End  : 52.2080099180681, 0.1175400000000
        // ======================
        // Line Start: 52.2080368693402, 0.1161260000000
        // Line End  : 52.2080368693402, 0.1175400000000
        // ======================

func ExampleAutoSuggestVoice() {
        api := what3words.NewGeocoder("[MK_API_KEY]")

        // inputVoice is JSON output from Vocon Hybrid vocoder

	inputVoice := `{"_isInGrammar":"yes","_isSpeech":"yes","_hypotheses":[{"_score":342516,"_startRule":"whatthreewordsgrammar#_main_","_conf":6546,"_endTimeMs":6360,"_beginTimeMs":1570,"_lmScore":300,"_items":[{"_type":"terminal","_score":34225,"_orthography":"tend","_conf":6964,"_endTimeMs":2250,"_beginTimeMs":1580},{"_type":"terminal","_score":47670,"_orthography":"artichokes","_conf":7176,"_endTimeMs":3180,"_beginTimeMs":2260},{"_type":"terminal","_score":43800,"_orthography":"poached","_conf":6181,"_endTimeMs":4060,"_beginTimeMs":3220}]},{"_score":342631,"_startRule":"whatthreewordsgrammar#_main_","_conf":6498,"_endTimeMs":6360,"_beginTimeMs":1570,"_lmScore":300,"_items":[{"_type":"terminal","_score":34340,"_orthography":"tent","_conf":6772,"_endTimeMs":2250,"_beginTimeMs":1580},{"_type":"terminal","_score":47670,"_orthography":"artichokes","_conf":7176,"_endTimeMs":3180,"_beginTimeMs":2260},{"_type":"terminal","_score":43800,"_orthography":"poached","_conf":6181,"_endTimeMs":4060,"_beginTimeMs":3220}]},{"_score":342668,"_startRule":"whatthreewordsgrammar#_main_","_conf":6474,"_endTimeMs":6360,"_beginTimeMs":1570,"_lmScore":300,"_items":[{"_type":"terminal","_score":34225,"_orthography":"tend","_conf":6964,"_endTimeMs":2250,"_beginTimeMs":1580},{"_type":"terminal","_score":47670,"_orthography":"artichokes","_conf":7176,"_endTimeMs":3180,"_beginTimeMs":2260},{"_type":"terminal","_score":41696,"_orthography":"perch","_conf":5950,"_endTimeMs":4020,"_beginTimeMs":3220}]},{"_score":342670,"_startRule":"whatthreewordsgrammar#_main_","_conf":6474,"_endTimeMs":6360,"_beginTimeMs":1570,"_lmScore":300,"_items":[{"_type":"terminal","_score":34379,"_orthography":"tinge","_conf":6705,"_endTimeMs":2250,"_beginTimeMs":1580},{"_type":"terminal","_score":47670,"_orthography":"artichokes","_conf":7176,"_endTimeMs":3180,"_beginTimeMs":2260},{"_type":"terminal","_score":43800,"_orthography":"poached","_conf":6181,"_endTimeMs":4060,"_beginTimeMs":3220}]},{"_score":342783,"_startRule":"whatthreewordsgrammar#_main_","_conf":6426,"_endTimeMs":6360,"_beginTimeMs":1570,"_lmScore":300,"_items":[{"_type":"terminal","_score":34340,"_orthography":"tent","_conf":6772,"_endTimeMs":2250,"_beginTimeMs":1580},{"_type":"terminal","_score":47670,"_orthography":"artichokes","_conf":7176,"_endTimeMs":3180,"_beginTimeMs":2260},{"_type":"terminal","_score":41696,"_orthography":"perch","_conf":5950,"_endTimeMs":4020,"_beginTimeMs":3220}]},{"_score":342822,"_startRule":"whatthreewordsgrammar#_main_","_conf":6402,"_endTimeMs":6360,"_beginTimeMs":1570,"_lmScore":300,"_items":[{"_type":"terminal","_score":34379,"_orthography":"tinge","_conf":6705,"_endTimeMs":2250,"_beginTimeMs":1580},{"_type":"terminal","_score":47670,"_orthography":"artichokes","_conf":7176,"_endTimeMs":3180,"_beginTimeMs":2260},{"_type":"terminal","_score":41696,"_orthography":"perch","_conf":5950,"_endTimeMs":4020,"_beginTimeMs":3220}]}],"_resultType":"NBest"}`
	autoreq := w3w.NewAutoSuggestRequest(inputVoice)
	autoreq.SetFocus(coords)
	autoreq.SetInputType("vocon-hybrid")

	resp, err := api.AutoSuggest(autoreq)
	if err != nil {
		fmt.Printf("Error: %s", err)
		return
	}
	fmt.Printf("======================\n")
	for _, suggestion := range resp.Suggestions {
		fmt.Printf("Country: %s\n", suggestion.Country)
		fmt.Printf("Nearest Place: %s\n", suggestion.NearestPlace)
		fmt.Printf("Words: %s\n", suggestion.Words)
		fmt.Printf("Distance to Focus km: %.3f\n", suggestion.DistanceToFocusKm)
		fmt.Printf("Rank: %d\n", suggestion.Rank)
		fmt.Printf("Language: %s\n", suggestion.Language)
		fmt.Printf("======================\n")
	}
        // Output:
        // ======================
        // Country: ZZ
        // Nearest Place: Angaur State, Angaur
        // Words: tend.artichokes.poached
        // Distance to Focus km: 12220.000
        // Rank: 1
        // Language: en
        // ======================
        // Country: ZZ
        // Nearest Place: Berbera, Woqooyi Galbeed
        // Words: tent.artichokes.poached
        // Distance to Focus km: 6112.000
        // Rank: 2
        // Language: en
        // ======================
        // Country: CA
        // Nearest Place: Rouyn-Noranda, Quebec
        // Words: tend.artichokes.perch
        // Distance to Focus km: 5382.000
        // Rank: 3
        // Language: en
        // ======================

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTo3waImpl

func ConvertTo3waImpl(geo *Geocoder, coords *Coordinates) (interface{}, error)

ConvertTo3waImpl perform REST API request over HTTP.

func ConvertToCoordsImpl

func ConvertToCoordsImpl(geo *Geocoder, words string) (interface{}, error)

ConvertToCoordsImpl perform REST API request over HPTTP.

func GridSectionImpl added in v0.1.0

func GridSectionImpl(geo *Geocoder, box *Box) (interface{}, error)

GridSectionImpl perform REST API request over HTTP.

func IsWhat3WordsAddress added in v0.3.5

func IsWhat3WordsAddress(address string) bool

func PackageVersion added in v0.3.0

func PackageVersion() string

PackageVersion returns Git version tag of current package

Types

type AutoSuggestRequest added in v0.1.0

type AutoSuggestRequest struct {
	Input             string
	NResults          int
	Focus             *Coordinates
	NFocusResults     int
	ClipToCountry     []string
	ClipToBoundingBox *Box
	ClipToCircle      *Circle
	ClipToPolyGon     *PolyGon
	InputType         string
	PreferLand        bool
}

AutoSuggestRequest response from REST API. Tags are used to map from the JSON response.

func NewAutoSuggestRequest added in v0.1.0

func NewAutoSuggestRequest(input string) *AutoSuggestRequest

NewAutoSuggestRequest instantiate a AutoSuggestRequest object.

func (*AutoSuggestRequest) InputTypeIsText added in v0.2.0

func (ar *AutoSuggestRequest) InputTypeIsText() bool

InputTypeIsText sets the Input type.

func (*AutoSuggestRequest) SetClipToBoundingBox added in v0.1.0

func (ar *AutoSuggestRequest) SetClipToBoundingBox(box *Box)

SetClipToBoundingBox sets the cliping box.

func (*AutoSuggestRequest) SetClipToCircle added in v0.1.0

func (ar *AutoSuggestRequest) SetClipToCircle(circle *Circle)

SetClipToCircle sets the clipping circle.

func (*AutoSuggestRequest) SetClipToCountry added in v0.1.0

func (ar *AutoSuggestRequest) SetClipToCountry(countries []string)

SetClipToCountry sets the list of countries.

func (*AutoSuggestRequest) SetClipToPolyGon added in v0.1.0

func (ar *AutoSuggestRequest) SetClipToPolyGon(polygon *PolyGon)

SetClipToPolyGon sets the clipping circle.

func (*AutoSuggestRequest) SetFocus added in v0.1.0

func (ar *AutoSuggestRequest) SetFocus(focus *Coordinates)

SetFocus sets the focus point.

func (*AutoSuggestRequest) SetInputType added in v0.1.0

func (ar *AutoSuggestRequest) SetInputType(input string) error

SetInputType sets the Input type.

func (*AutoSuggestRequest) SetNFocusResults added in v0.1.0

func (ar *AutoSuggestRequest) SetNFocusResults(number int) error

SetNFocusResults sets the Number of focus results parameter.

func (*AutoSuggestRequest) SetNResults added in v0.1.0

func (ar *AutoSuggestRequest) SetNResults(number int) error

SetNResults sets the Number of results parameter.

func (*AutoSuggestRequest) SetPreferLand added in v0.1.0

func (ar *AutoSuggestRequest) SetPreferLand(land bool)

SetPreferLand sets the PeferLand type.

type AutoSuggestRequestInterface added in v0.3.0

type AutoSuggestRequestInterface interface {
	SetNResults(number int) error
	SetFocus(focus *Coordinates)
	SetNFocusResults(number int) error
	SetClipToCountry(countries []string)
	SetClipToBoundingBox(box *Box)
	SetClipToCircle(circle *Circle)
	SetClipToPolyGon(polygon *PolyGon)
	SetInputType(input string) error
	InputTypeIsText() bool
	SetPreferLand(land bool)
}

AutoSuggestRequestInterface interface definiton

type AutoSuggestResponse added in v0.1.0

type AutoSuggestResponse struct {
	Suggestions []*Suggestion `json:"suggestions"`
}

AutoSuggestResponse response from REST API. Tags are used to map from the JSON response.

func AutoSuggestImpl added in v0.1.0

func AutoSuggestImpl(geo *Geocoder, areq *AutoSuggestRequest) (*AutoSuggestResponse, error)

AutoSuggestImpl perform REST API request over HTTP.

func NewAutoSuggestResponse added in v0.1.0

func NewAutoSuggestResponse() *AutoSuggestResponse

NewAutoSuggestResponse instantiate a AutoSuggestResponse object.

type Box added in v0.1.0

type Box struct {
	SouthWest *Coordinates `json:"southwest"`
	NorthEast *Coordinates `json:"northeast"`
}

Box defines an area bounded by two coordinates. South West and North East points of the Box define its extent. // Tags are used to map from the JSON response.

func NewBox added in v0.1.0

func NewBox(sw *Coordinates, ne *Coordinates) (*Box, error)

NewBox returns a Box region

func (*Box) String added in v0.1.0

func (box *Box) String() string

String returns a string suitable for a URL parameter.

type Circle added in v0.1.0

type Circle struct {
	Centre *Coordinates `json:"centre"`
	Radius float64      `json:"radius"`
}

Circle defines an area bounded by a coordinate and a radius. Tags are used to map from the JSON response.

func NewCircle added in v0.1.0

func NewCircle(centre *Coordinates, radius float64) (*Circle, error)

NewCircle returns a circular region

func (*Circle) String added in v0.1.0

func (circle *Circle) String() string

String returns a string suitable for a URL parameter.

type ConvertTo3waResponse

type ConvertTo3waResponse struct {
	Response
}

ConvertTo3waResponse response from REST API. Tags are used to map from the JSON response.

func NewConvertTo3waResponse

func NewConvertTo3waResponse() *ConvertTo3waResponse

NewConvertTo3waResponse instantiate a ConvertTo3waResponse object.

type ConvertToCoordsResponse

type ConvertToCoordsResponse struct {
	Response
}

ConvertToCoordsResponse response from REST API. Tags are used to map from the JSON response.

func NewConvertToCoordsResponse

func NewConvertToCoordsResponse() *ConvertToCoordsResponse

NewConvertToCoordsResponse instantiate a ConvertToCoordsResponse object.

type Coordinates

type Coordinates struct {
	Latitude  float64 `json:"lat"`
	Longitude float64 `json:"lng"`
}

Coordinates struct with latitude and longitude. Tags are used to map from the JSON response.

func NewCoordinates

func NewCoordinates(lat float64, lon float64) (*Coordinates, error)

NewCoordinates return a new Coordinates object. constructed from latitude and longitude values. It verifies range of latitude and longitude are correct.

func (*Coordinates) SetLat

func (coord *Coordinates) SetLat(lat float64) error

SetLat sets the Latitude in a Coordinates object. verifying range of latitude is correct.

func (*Coordinates) SetLon

func (coord *Coordinates) SetLon(lon float64) error

SetLon sets the Longitude in a Coordinates object. verifying range of longitude is correct.

func (*Coordinates) String added in v0.1.0

func (coord *Coordinates) String() string

String returns a string suitable for a URL parameter.

type CoordinatesInterface added in v0.3.0

type CoordinatesInterface interface {
	SetLat(lat float64) error
	SetLon(lon float64) error
	String() string
}

CoordinatesInterface interface definition

type ErrorDetails

type ErrorDetails struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorDetails response from REST API. Tags are used to map from the JSON response.

type Geocoder

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

Geocoder struct with information needed to make HTTP API calls.

func NewGeocoder

func NewGeocoder(apiKey string) *Geocoder

NewGeocoder return a new Geocoder. Default values ensure W3W API V3 is used, json is returned and English is the default language.

func (*Geocoder) APIKey

func (geocoder *Geocoder) APIKey() string

APIKey get the API Key from a Geocoder.

func (*Geocoder) AutoSuggest added in v0.1.0

func (geocoder *Geocoder) AutoSuggest(request *AutoSuggestRequest) (*AutoSuggestResponse, error)

AutoSuggest suggests a list of 3 word addresses from an imprecise input.

func (*Geocoder) AvailableLanguages added in v0.1.0

func (geocoder *Geocoder) AvailableLanguages() (*LanguagesResponse, error)

AvailableLanguages returns a list of available languages.

func (*Geocoder) BaseURL

func (geocoder *Geocoder) BaseURL() *url.URL

BaseURL get the base URL from a Geocoder.

func (*Geocoder) ConvertTo3wa

func (geocoder *Geocoder) ConvertTo3wa(coord *Coordinates) (*ConvertTo3waResponse, error)

ConvertTo3wa converts a set of coordinates to a 3 word address.

func (*Geocoder) ConvertTo3waGeoJSON added in v0.1.2

func (geocoder *Geocoder) ConvertTo3waGeoJSON(coord *Coordinates) (*geojson.FeatureCollection, error)

ConvertTo3waGeoJSON converts a set of coordinates to a 3 word address.

func (*Geocoder) ConvertToCoords

func (geocoder *Geocoder) ConvertToCoords(words string) (*ConvertToCoordsResponse, error)

ConvertToCoords converts a 3 word address to coordinates.

func (*Geocoder) ConvertToCoordsGeoJSON added in v0.1.2

func (geocoder *Geocoder) ConvertToCoordsGeoJSON(words string) (*geojson.FeatureCollection, error)

ConvertToCoordsGeoJSON converts a 3 word address to coordinates.

func (*Geocoder) Format

func (geocoder *Geocoder) Format() string

Format get the Format from a Geocoder.

func (*Geocoder) GridSection added in v0.1.0

func (geocoder *Geocoder) GridSection(box *Box) (*GridSectionResponse, error)

GridSection returns a list of lines from a box.

func (*Geocoder) GridSectionGeoJSON added in v0.1.2

func (geocoder *Geocoder) GridSectionGeoJSON(box *Box) (*geojson.FeatureCollection, error)

GridSectionGeoJSON returns a list of lines from a box.

func (*Geocoder) IsFormatGeoJSON added in v0.1.2

func (geocoder *Geocoder) IsFormatGeoJSON() bool

IsFormatGeoJSON test the Format for a Geocoder.

func (*Geocoder) IsFormatJSON added in v0.1.2

func (geocoder *Geocoder) IsFormatJSON() bool

IsFormatJSON test the Format for a Geocoder.

func (*Geocoder) Language

func (geocoder *Geocoder) Language() string

Language get the language from a Geocoder.

func (*Geocoder) SetAPIKey

func (geocoder *Geocoder) SetAPIKey(apiKey string)

SetAPIKey set the API Key in a Geocoder.

func (*Geocoder) SetBaseURL added in v0.2.2

func (geocoder *Geocoder) SetBaseURL(urlString string) error

SetBaseURL set the base URL for a Geocoder.

func (*Geocoder) SetFormat added in v0.1.2

func (geocoder *Geocoder) SetFormat(format string) error

SetFormat set the Format for a Geocoder.

func (*Geocoder) SetFormatGeoJSON added in v0.1.2

func (geocoder *Geocoder) SetFormatGeoJSON()

SetFormatGeoJSON set format as GeoJSON

func (*Geocoder) SetFormatJSON added in v0.1.2

func (geocoder *Geocoder) SetFormatJSON()

SetFormatJSON set format as JSON

func (*Geocoder) SetLanguage

func (geocoder *Geocoder) SetLanguage(language string)

SetLanguage set the language in a Geocoder.

func (*Geocoder) Version

func (geocoder *Geocoder) Version() string

Version get the API version from a Geocoder.

type GeocoderInterface added in v0.3.0

type GeocoderInterface interface {
	SetAPIKey(apiKey string)
	APIKey() string
	BaseURL() *url.URL
	SetBaseURL(urlString string) error
	Format() string
	SetFormat(format string) error
	SetFormatJSON()
	SetFormatGeoJSON()
	IsFormatJSON() bool
	IsFormatGeoJSON() bool
	Language() string
	SetLanguage(language string)
	Version() string
	ConvertTo3wa(coord *Coordinates) (*ConvertTo3waResponse, error)
	ConvertTo3waGeoJSON(coord *Coordinates) (*geojson.FeatureCollection, error)
	ConvertToCoords(words string) (*ConvertToCoordsResponse, error)
	ConvertToCoordsGeoJSON(words string) (*geojson.FeatureCollection, error)
	AutoSuggest(request *AutoSuggestRequest) (*AutoSuggestResponse, error)
	GridSection(box *Box) (*GridSectionResponse, error)
	GridSectionGeoJSON(box *Box) (*geojson.FeatureCollection, error)
	AvailableLanguages() (*LanguagesResponse, error)
}

GeocoderInterface interface to object

type GridSectionResponse added in v0.1.0

type GridSectionResponse struct {
	Lines []*Line `json:"lines"`
}

GridSectionResponse response from REST API. Tags are used to map from the JSON response.

func NewGridSectionResponse added in v0.1.0

func NewGridSectionResponse() *GridSectionResponse

NewGridSectionResponse instantiate a GridSectionResponse object.

type Language added in v0.1.0

type Language struct {
	NativeName string `json:"nativeName"`
	Code       string `json:"code"`
	Name       string `json:"name"`
}

Language response from REST API Tags are used to map from the JSON response.

type LanguagesResponse added in v0.1.0

type LanguagesResponse struct {
	Languages []Language `json:"languages"`
}

LanguagesResponse response from REST API. Tags are used to map from the JSON response.

func AvailableLanguagesImpl added in v0.1.0

func AvailableLanguagesImpl(geo *Geocoder) (*LanguagesResponse, error)

AvailableLanguagesImpl perform REST API request over HTTP.

func NewLanguagesResponse added in v0.1.0

func NewLanguagesResponse() *LanguagesResponse

NewLanguagesResponse instantiate a LanguagesResponse object.

type Line added in v0.1.0

type Line struct {
	Start *Coordinates `json:"start"`
	End   *Coordinates `json:"end"`
}

Line object. Tags are used to map from the JSON response.

type PolyGon added in v0.1.0

type PolyGon struct {
	Path []*Coordinates `json:"path"`
}

PolyGon defines an area bounded by a slice of coordinates. Tags are used to map from the JSON response.

func NewPolyGon added in v0.1.0

func NewPolyGon(path []*Coordinates) *PolyGon

NewPolyGon returns a polygon region

func (*PolyGon) String added in v0.1.0

func (polygon *PolyGon) String() string

String returns a string suitable for a URL parameter.

type Response added in v0.1.0

type Response struct {
	Country      string       `json:"country"`
	Square       *Box         `json:"square"`
	NearestPlace string       `json:"nearestPlace"`
	Coordinates  *Coordinates `json:"coordinates"`
	Words        string       `json:"words"`
	Language     string       `json:"language"`
	Map          string       `json:"map"`
}

Response generic response from REST API. Tags are used to map from the JSON response.

type ResponseError

type ResponseError struct {
	Error ErrorDetails `json:"error"`
}

ResponseError response from REST API. Tags are used to map from the JSON response.

func NewResponseError

func NewResponseError() *ResponseError

NewResponseError instantiate a ResponseError object.

func (*ResponseError) AsError added in v0.1.0

func (respErr *ResponseError) AsError() error

AsError renders ResponseError in error form.

func (*ResponseError) Code

func (respErr *ResponseError) Code() string

Code of error message.

func (*ResponseError) Message

func (respErr *ResponseError) Message() string

Message of error message.

func (*ResponseError) String added in v0.1.0

func (respErr *ResponseError) String() string

String renders ResponseError in string form.

type ResponseErrorInterface added in v0.3.0

type ResponseErrorInterface interface {
	Code() string
	Message() string
	String() string
	AsError() error
}

ResponseErrorInterface interface definition

type ShapeInterface added in v0.3.0

type ShapeInterface interface {
	String() string
}

ShapeInterface common operations on shapes

type Suggestion added in v0.1.0

type Suggestion struct {
	Country           string  `json:"country"`
	NearestPlace      string  `json:"nearestPlace"`
	Words             string  `json:"words"`
	DistanceToFocusKm float64 `json:"distanceToFocusKm"`
	Rank              int     `json:"rank"`
	Language          string  `json:"language"`
}

Suggestion response from REST API. Tags are used to map from the JSON response.

Jump to

Keyboard shortcuts

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