Documentation
¶
Index ¶
- Variables
- type Client
- type HTTPError
- type InvalidCoordinateError
- type Location
- type Option
- func WithBaseURL(baseURL string) Option
- func WithContactEmail(email string) Option
- func WithCountryCodes(countryCodes ...string) Option
- func WithHTTPClient(client *http.Client) Option
- func WithPreferredLanguage(language string) Option
- func WithResultLimit(limit int) Option
- func WithUserAgent(userAgent string) Option
- type SearchOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrEmptyAddress = errors.New("nominatim: empty address") ErrNoResults = errors.New("nominatim: no results") ErrInvalidJSON = errors.New("nominatim: invalid JSON response") ErrInvalidCoordinate = errors.New("nominatim: invalid coordinate") ErrMissingUserAgent = errors.New("nominatim: user agent is required") ErrInvalidLimit = errors.New("nominatim: result limit must be greater than zero") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Geocode ¶
Example ¶
package main
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
nominatim "github.com/teddy-vltn/nominatim-go-lite"
)
func main() {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`[{"lat":"48.8583701","lon":"2.2944813","display_name":"Eiffel Tower, Paris, France","type":"tourism","importance":0.9}]`))
}))
defer server.Close()
client := nominatim.NewClient(
nominatim.WithBaseURL(server.URL),
nominatim.WithUserAgent("my-app/1.0"),
nominatim.WithContactEmail("developer@example.com"),
)
location, err := client.Geocode(
context.Background(),
"5 Avenue Anatole France, 75007 Paris, France",
)
if err != nil {
panic(err)
}
fmt.Println(location.Latitude, location.Longitude)
}
Output: 48.8583701 2.2944813
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, address string, options ...SearchOption) ([]Location, error)
Example ¶
package main
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
nominatim "github.com/teddy-vltn/nominatim-go-lite"
)
func main() {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(`[
{"lat":"48.8566","lon":"2.3522","display_name":"Paris, France","type":"city","importance":0.9},
{"lat":"33.6609","lon":"-95.5555","display_name":"Paris, Texas","type":"city","importance":0.6}
]`))
}))
defer server.Close()
client := nominatim.NewClient(
nominatim.WithBaseURL(server.URL),
nominatim.WithUserAgent("my-app/1.0"),
)
locations, err := client.Search(
context.Background(),
"Paris",
nominatim.WithSearchLimit(2),
)
if err != nil {
panic(err)
}
fmt.Println(len(locations))
}
Output: 2
type InvalidCoordinateError ¶
func (*InvalidCoordinateError) Error ¶
func (e *InvalidCoordinateError) Error() string
func (*InvalidCoordinateError) Unwrap ¶
func (e *InvalidCoordinateError) Unwrap() error
type Option ¶
type Option func(*Client)
func WithBaseURL ¶
func WithContactEmail ¶
func WithCountryCodes ¶
func WithHTTPClient ¶
func WithPreferredLanguage ¶
func WithResultLimit ¶
func WithUserAgent ¶
type SearchOption ¶
type SearchOption func(*searchConfig)
func WithSearchCountryCodes ¶
func WithSearchCountryCodes(countryCodes ...string) SearchOption
func WithSearchLimit ¶
func WithSearchLimit(limit int) SearchOption
func WithSearchPreferredLanguage ¶
func WithSearchPreferredLanguage(language string) SearchOption
Click to show internal directories.
Click to hide internal directories.