geo

package
v0.0.0-...-d5107d6 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

From: https://github.com/nf/geocode/blob/master/geocode.go, by Jonathan Ingram

Package geocode is an interface to mapping APIs. This includes geocoding as well as routing.

== Google: http://code.google.com/apis/maps/documentation/geocoding/
== OSM: http://wiki.openstreetmap.org/wiki/Nominatim
== YOURS: http://wiki.openstreetmap.org/wiki/YOURS

Index

Constants

View Source
const (
	/* Request Type */
	GEOCODE RequestType = 1
	ROUTE   RequestType = 2

	/* Geocoding URLs */
	GOOGLE = "http://maps.googleapis.com/maps/api/geocode/json"
	OSM    = "http://open.mapquestapi.com/nominatim/v1/reverse.php"

	/* Routing URLs */
	YOURS        = "http://www.yournavigation.org/api/1.0/gosmore.php"
	YOURS_HEADER = "github.com/talmai/geocode" // change this to your website!
)

Variables

This section is empty.

Functions

func GetAddress

func GetAddress(lat, lng float64) (string, error)

func GetLatLng

func GetLatLng(addr string) (float64, float64, error)

Types

type Bounds

type Bounds struct {
	NorthEast, SouthWest Point
}

func (Bounds) String

func (b Bounds) String() string

type Geometry

type Geometry struct {
	Bounds   Bounds
	Location Point
	Type     string
	Viewport Bounds
}

type GoogleAddressPart

type GoogleAddressPart struct {
	Name      string `json:"long_name"`
	ShortName string `json:"short_name"`
	Types     []string
}

type GoogleResponse

type GoogleResponse struct {
	Results []*GoogleResult
}

type GoogleResult

type GoogleResult struct {
	/*
		{
		   "results" : [
		      {
		         "address_components" : [
		            {
		               "long_name" : "1600",
		               "short_name" : "1600",
		               "types" : [ "street_number" ]
		            },
		            {
		               "long_name" : "Amphitheatre Pkwy",
		               "short_name" : "Amphitheatre Pkwy",
		               "types" : [ "route" ]
		            },
		            {
		               "long_name" : "Mountain View",
		               "short_name" : "Mountain View",
		               "types" : [ "locality", "political" ]
		            },
		            {
		               "long_name" : "Santa Clara",
		               "short_name" : "Santa Clara",
		               "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" ]
		            },
		            {
		               "long_name" : "94043",
		               "short_name" : "94043",
		               "types" : [ "postal_code" ]
		            }
		         ],
		         "formatted_address" : "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
		         "geometry" : {
		            "location" : {
		               "lat" : 37.42291810,
		               "lng" : -122.08542120
		            },
		            "location_type" : "ROOFTOP",
		            "viewport" : {
		               "northeast" : {
		                  "lat" : 37.42426708029149,
		                  "lng" : -122.0840722197085
		               },
		               "southwest" : {
		                  "lat" : 37.42156911970850,
		                  "lng" : -122.0867701802915
		               }
		            }
		         },
		         "types" : [ "street_address" ]
		      }
		   ],
		   "status" : "OK"
		}
	*/
	Address      string               `json:"formatted_address"`
	AddressParts []*GoogleAddressPart `json:"address_components"`
	Geometry     *Geometry
	Types        []string
}

type OSMAddressPart

type OSMAddressPart struct {
	HouseNumber string `json:"house_number"`
	Name        string `json:"road"`
	City        string `json:"city"`
	State       string `json:"state"`
}

type OSMResponse

type OSMResponse struct {
	// OSM stuff
	/*
		{"place_id":"62762024",
		"licence":"Data \u00a9 OpenStreetMap contributors, ODbL 1.0. http:\/\/www.openstreetmap.org\/copyright",
		"osm_type":"way",
		"osm_id":"90394420",
		"lat":"52.548781",
		"lon":"-1.81626870827795",
		"display_name":"137, Pilkington Avenue, Castle Vale, Birmingham, West Midlands, England, B72 1LH, United Kingdom",
		"address":{
			"house_number":"137",
			"road":"Pilkington Avenue",
			"suburb":"Castle Vale",
			"city":"Birmingham",
			"county":"West Midlands",
			"state_district":"West Midlands",
			"state":"England",
			"postcode":"B72 1LH",
			"country":"United Kingdom",
			"country_code":"gb"
		}}
	*/
	Address      string          `json:"display_name"`
	AddressParts *OSMAddressPart `json:"address"`
	Lat          string          `json:"lat"`
	Lng          string          `json:"lon"`
}

type Point

type Point struct {
	Lat, Lng float64
}

func (Point) String

func (p Point) String() string

type ProviderApiLocation

type ProviderApiLocation string

type Request

type Request struct {
	HTTPClient *http.Client
	Provider   ProviderApiLocation
	Type       RequestType

	// For geocoding, one (and only one) of these must be set.
	Address  string
	Location *Point

	// For routing, bounds must be set
	Bounds *Bounds // used by GOOGLE and YOURS

	Limit    int64  // used by OSM
	Region   string // used by GOOGLE
	Language string // used by GOOGLE
	Sensor   bool   // used by GOOGLE
	// contains filtered or unexported fields
}

func (*Request) Lookup

func (r *Request) Lookup(transport http.RoundTripper) (*Response, error)

func (*Request) Route

func (r *Request) Route(transport http.RoundTripper) (*Response, error)

func (*Request) SendAPIRequest

func (r *Request) SendAPIRequest(transport http.RoundTripper) (*Response, error)

SendAPIRequest makes the Request to the provider using the provided transport (or http.DefaultTransport if nil).

func (*Request) Values

func (r *Request) Values() url.Values

type RequestType

type RequestType int

type Response

type Response struct {
	Status      string
	QueryString string
	Found       string
	Count       int
	*GoogleResponse
	*OSMResponse
	*YOURSResponse
}

type YOURSProperties

type YOURSProperties struct {
	Distance     string `json:"distance"`
	Instructions string `json:"description"`
	TravelTime   string `json:"traveltime"`
}

type YOURSResponse

type YOURSResponse struct {
	/*
		{
		  "type": "LineString",
		  "crs": {
		    "type": "name",
		    "properties": {
		      "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
		    }
		  },
		  "coordinates":
		  [
			[-118.604871, 34.172300]
			,[-118.604872, 34.172078]
			,[-118.604870, 34.171966]
			,[-118.500806, 34.235753]
			,[-118.500814, 34.236146]
		  ],
		  "properties": {
		    "distance": "17.970238",
		    "description": "Go straight ahead.<br>Follow the road for...",
		    "traveltime": "1018"
		    }
		}
	*/
	Coordinates [][]float64      `json:"coordinates"`
	Properties  *YOURSProperties `json:"properties"`
}

currently doesn't

Jump to

Keyboard shortcuts

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