geocodio

package module
v0.0.0-...-bf8e1f3 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2020 License: MIT Imports: 9 Imported by: 0

README

geocodio

GoDoc Go Report Card

Go client for Geocodio API v1

Usage

Geocode
import(
  "github.com/stevepartridge/geocodio"
  "fmt"
)

func main() {
  Geocodio, err := geocodio.NewGeocodio("YOUR_API_KEY")
	if err != nil {
		panic(err)
	}
	result, err := Geocodio.Geocode("42370 Bob Hope Dr, Rancho Mirage, CA")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Geocode Result %v", result)
	
  result, err = Geocodio.GeocodeByComponents("42370 Bob Hope Dr", "Rancho Mirage", "CA", "", "USA", "1")
	if err != nil {
		panic(err)
	}
	fmt.Printf("Geocode Result %v", result)
}
Reverse Geocode
import(
  "github.com/stevepartridge/geocodio"
  "fmt"
)

func main() {
  Geocodio, err := geocodio.NewGeocodio("YOUR_API_KEY")
	if err != nil {
		panic(err)
	}
	result, err := Geocodio.ReverseGeocode(38.9002898, -76.9990361)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Reverse Geocode Result %v", result)
}

Tests

You can run the tests leveraging your API key as an enviroment variable from terminal (*nix).

API_KEY=<YOUR_API_KEY> go test -v -cover

TODO

Fix breaking changes (see https://www.geocod.io/docs/#changelog):

  • The census append now supports vintage years, data is keyed by year instead of just returning a single year
  • Name property has been renamed to abbreviation
  • Name is now the full timezone name in a tzdb-compatible format

Documentation

Index

Constants

View Source
const (
	// GeocodioAPIBaseURLv1 is the Geocod.io Base URL
	GeocodioAPIBaseURLv1 = "https://api.geocod.io/v1.4"
)

Variables

This section is empty.

Functions

func CombineComponents

func CombineComponents(street, city, state, postalCode, country string, limit int) (map[string]string, error)

Types

type Address

type Address struct {
	Components   Components `json:"address_components"`
	Formatted    string     `json:"formatted_address"`
	Location     Location   `json:"location"`
	Accuracy     float64    `json:"accuracy"`
	AccuracyType string     `json:"accuracy_type"`
	Source       string     `json:"source"`
	Fields       Fields     `json:"fields,omitempty"`
}

type Components

type Components struct {
	Number          string `json:"number"`
	Street          string `json:"street"`
	Suffix          string `json:"suffix"`
	SecondaryNumber string `json:"secondarynumber"`
	SecondaryUnit   string `json:"secondaryunit"`
	PostDirectional string `json:"postdirectional"`
	FormattedStreet string `json:"formatted_street"`
	City            string `json:"city"`
	State           string `json:"state"`
	Zip             string `json:"zip"`
	County          string `json:"county,omitempty"`
	Country         string `json:"country"`
	PreDirectional  string `json:"PreDirectional"`
	Prefix          string `json:"Prefix"`
}

type CongressionalDistrict

type CongressionalDistrict struct {
	Name           string `json:"name"`
	DistrictNumber int    `json:"district_number"`
	CongressNumber string `json:"congress_number"`
	CongressYears  string `json:"congress_years"`
}

type Fields

type Fields struct {
	Timezone                  Timezone                  `json:"timezone,omitempty"`
	CongressionalDistrict     CongressionalDistrict     `json:"congressional_district,omitempty"`
	StateLegislativeDistricts StateLegislativeDistricts `json:"state_legislative_districts,omitempty"`
}

Fields

type GeocodeResult

type GeocodeResult struct {
	Input struct {
		AddressComponents Components `json:"address_components"`
	} `json:"input,omitempty"`
	Results []Address `json:"results"`
	Debug   struct {
		RawResponse  []byte `json:"-"`
		RequestedURL string `json:"requested_url"`
		Status       string `json:"status"`
		StatusCode   int    `json:"status_code"`
	} `json:"-"`
}

GeocodeResponse

func (*GeocodeResult) ResponseAsString

func (self *GeocodeResult) ResponseAsString() string

type Geocodio

type Geocodio struct {
	APIKey string
}

Geocodio is the base struct

func NewGeocodio

func NewGeocodio(apiKey string) (*Geocodio, error)

NewGeocodio is a helper to create new Geocodio pointer

func (*Geocodio) Call

func (g *Geocodio) Call(path string, query map[string]string) (GeocodeResult, error)

Call uses basic (GET) method to make a request to the API

func (*Geocodio) Geocode

func (g *Geocodio) Geocode(address string) (GeocodeResult, error)

Geocode single address See: http://geocod.io/docs/#toc_4

func (*Geocodio) GeocodeAndReturnCongressionalDistrict

func (g *Geocodio) GeocodeAndReturnCongressionalDistrict(address string) (GeocodeResult, error)

GeocodeAndReturnCongressionalDistrict will geocode and include Congressional District in the fields response

func (*Geocodio) GeocodeAndReturnStateLegislativeDistricts

func (g *Geocodio) GeocodeAndReturnStateLegislativeDistricts(address string) (GeocodeResult, error)

GeocodeAndReturnStateLegislativeDistricts will geocode and include State Legislative Districts in the fields response

func (*Geocodio) GeocodeAndReturnTimezone

func (g *Geocodio) GeocodeAndReturnTimezone(address string) (GeocodeResult, error)

GeocodeAndReturnTimezone will geocode and include Timezone in the fields response

func (*Geocodio) GeocodeByComponents

func (g *Geocodio) GeocodeByComponents(street, city, state, postalCode, country string, limit int) (GeocodeResult, error)

func (*Geocodio) GeocodeByComponentsAndReturnTimezone

func (g *Geocodio) GeocodeByComponentsAndReturnTimezone(street, city, state, postalCode, country string, limit int) (GeocodeResult, error)

GeocodeAndReturnTimezone will geocode and include Timezone in the fields response

func (*Geocodio) GeocodeReturnFields

func (g *Geocodio) GeocodeReturnFields(address string, fields ...string) (GeocodeResult, error)

GeocodeReturnFields will geocode and includes additional fields in response

 	See: http://geocod.io/docs/#toc_22
	Note:
		Each field counts as an additional lookup each

func (*Geocodio) ReverseGeocode

func (g *Geocodio) ReverseGeocode(latitude, longitude float64) (GeocodeResult, error)
See: http://geocod.io/docs/#toc_16

ReverseGeocode does a reverse geocode look up for a single coordinate

type Location

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

type StateLegislativeDistrict

type StateLegislativeDistrict struct {
	Name           string `json:"name"`
	DistrictNumber string `json:"district_number"`
}

type StateLegislativeDistricts

type StateLegislativeDistricts struct {
	House  StateLegislativeDistrict `json:"house"`
	Senate StateLegislativeDistrict `json:"senate"`
}

type Timezone

type Timezone struct {
	Name         string `json:"name"`
	UTCOffset    int    `json:"utc_offset"`
	ObservesDST  bool   `json:"observes_dst"`
	Abbreviation string `json:"abbreviation"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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