geocode

package
v0.15.5 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2018 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

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

Address contains details of a place.

type Geocode

type Geocode struct {
	AreaCode      string  `json:"area_code"`
	Asn           string  `json:"asn"`
	City          string  `json:"city"`
	ContinentCode string  `json:"continent_code"`
	Country       string  `json:"country"`
	CountryCode   string  `json:"country_code"`
	CountryCode3  string  `json:"country_code3"`
	DMACode       string  `json:"dma_code"`
	Error         string  `json:"error"`
	IP            string  `json:"ip"`
	Isp           string  `json:"isp"`
	Latitude      float64 `json:"latitude"`
	Longitude     float64 `json:"longitude"`
	PostalCode    string  `json:"postal_code"`
	Region        string  `json:"region"`
	RegionCode    string  `json:"region_code"`
	Timezone      string  `json:"timezone"`
}

Geocode response from www.telize.com/geoip comes back like:

{
    timezone: "America/New_York",
    isp: "Road Runner HoldCo LLC",
    region_code: "NY",
    country: "United States",
    dma_code: "0",
    area_code: "0",
    region: "New York",
    ip: "74.71.83.142",
    asn: "AS11351",
    continent_code: "NA",
    city: "New York",
    postal_code: "10128",
    longitude: -73.9512,
    latitude: 40.7805,
    country_code: "US",
    country_code3: "USA"
}

func Autolocate

func Autolocate() (geocode Geocode, err error)

Autolocate gets the requesters geocode response based off their IP address.

func IPLocate

func IPLocate(ip string) (geocode Geocode, err error)

IPLocate gets the requesters geocode response based off an IP address.

func Locate

func Locate(location, server string) (geocode Geocode, err error)

Locate gets the geocode data of a location that is passed as a string.

type Geometry

type Geometry struct {
	Bounds       map[string]Location `json:"bounds"`
	Location     Location            `json:"location"`
	LocationType string              `json:"location_type"`
	Viewport     map[string]Location `json:"viewport"`
}

Geometry contains location data.

type Location

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

Location contains lat and lng.

type Request

type Request struct {
	Location string `json:"location"`
}

Request describes the request posted to the geocode api.

type Response

type Response struct {
	Results      []Result `json:"results"`
	Status       string   `json:"status"`
	ErrorMessage string   `json:"error_message"`
}

Response is the response from the Google Geocoding API it comes back like the following:

{
  "results" : [
     {
        "address_components" : [
           {
              "long_name" : "Manhattan Beach",
              "short_name" : "Manhattan Beach",
              "types" : [ "locality", "political" ]
           },
           {
              "long_name" : "Los Angeles County",
              "short_name" : "Los Angeles County",
              "types" : [ "administrative_area_level_2", "political" ]
           },
           {
              "long_name" : "California",
              "short_name" : "CA",
              "types" : [ "administrative_area_level_1", "political" ]
           },
           {
              "long_name" : "United States",
              "short_name" : "US",
              "types" : [ "country", "political" ]
           }
        ],
        "formatted_address" : "Manhattan Beach, CA, USA",
        "geometry" : {
           "bounds" : {
              "northeast" : {
                 "lat" : 33.906185,
                 "lng" : -118.3785991
              },
              "southwest" : {
                 "lat" : 33.8728038,
                 "lng" : -118.4234639
              }
           },
           "location" : {
              "lat" : 33.8847361,
              "lng" : -118.4109089
           },
           "location_type" : "APPROXIMATE",
           "viewport" : {
              "northeast" : {
                 "lat" : 33.906185,
                 "lng" : -118.3785991
              },
              "southwest" : {
                 "lat" : 33.8728038,
                 "lng" : -118.4234639
              }
           }
        },
        "place_id" : "ChIJL2Ow4sWzwoARIEUV9NRRAwc",
        "types" : [ "locality", "political" ]
     }
  ],
  "status" : "OK"
}

type Result

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

Result is the result from the Google geocoding API.

Jump to

Keyboard shortcuts

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