nominatim

package module
v0.0.0-...-9f54a6b Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2018 License: BSD-2-Clause Imports: 4 Imported by: 0

README

Go client of https://wiki.openstreetmap.org/wiki/Nominatim

type Place struct {
    Name    string  `json:"display_name"`
    Lat     string  `json:"lat"`
    Lon     string  `json:"lon"`
}

search := url.Values{}
search.Set(nominatim.FieldCountry, "France")
search.Set(nominatim.FieldCity, "Poitiers")
search.Set(nominatim.FieldStreet, nominatim.Street{
    HouseNumber: 47,
    ValidNumber: true,
    StreetName: "Avenue des Terrasses",
}.String())

jsonResp, _ := nominatim.Client{}.Lookup(search)

defer jsonResp.Close()

var places []Place

json.NewDecoder(jsonResp).Decode(&places)

nominatim/service:


import "github.com/varyoo/nominatim/service"

type SearchJob struct {
    City    string
    Street  nominatim.Street
}

func (j SearchJob) Search() url.Values {
   s := url.Values{}
   s.Set(nominatim.FieldCity, j.City)
   s.Set(nominatim.FieldStreet, j.Street.String())
   return s
}

// SetCoordinates is called as soon as the Nominatim search completes
func (j SearchJob) SetCoordinates(jsonResp io.ReadCloser) error {
    defer jsonResp.Close()

    var places []Place

    if err := json.NewDecoder(jsonResp).Decode(&places); err != nil {
        return err
    }

    for _, p := range places {
        log.Println(p.Name)
    }
}

func localize() {
    s := New(nominatim.Client{})

    // start the Nominatim Goroutine
    go s.Go()

    ctx, _ := context.WithTimeout(context.Backgroudn(), time.Second * 3)

    s.Localize(ctx, SearchJob{"Poitiers", nominatim.Street{
        HouseNumber: 47,
        ValidNumber: true,
        StreetName: "Avenue des Terrasses",
    })
}

Documentation

Index

Constants

View Source
const (
	FieldPostalCode string = "postalcode"
	FieldCountry    string = "country"
	FieldStreet     string = "street"
	FieldCity       string = "city"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Email      string
	HTTPClient http.Client
}

func (*Client) Lookup

func (c *Client) Lookup(fields url.Values) (io.ReadCloser, error)

type Street

type Street struct {
	ValidNumber bool
	HouseNumber int64
	StreetName  string
}

func (Street) String

func (s Street) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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