mapbox

package module
v0.0.0-...-0de3074 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2018 License: MIT Imports: 12 Imported by: 1

README

mapbox

Mapbox Go API

Documentation

Overview

Example (Client_LookupLatLon)
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/orijtech/mapbox"
)

func main() {
	client, err := mapbox.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	resp, err := client.LookupLatLon(context.Background(), 38.8971, -77.0366)
	if err != nil {
		log.Fatal(err)
	}

	for i, feat := range resp.Features {
		fmt.Printf("Match: #%d Name: %q Relevance: %v Center: %#v\n", i, feat.PlaceName, feat.Relevance, feat.Center)
		for j, ctx := range feat.Context {
			fmt.Printf("\tContext: #%d:: %#v\n", j, ctx)
		}
		fmt.Printf("\n\n")
	}
}
Output:

Example (Client_LookupPlace)
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/orijtech/mapbox"
)

func main() {
	client, err := mapbox.NewClient()
	if err != nil {
		log.Fatal(err)
	}

	// Time for some tacos, let's lookup that new spot.
	match, err := client.LookupPlace(context.Background(), "Tacquerias El Farolito")
	if err != nil {
		log.Fatal(err)
	}

	for i, feat := range match.Features {
		fmt.Printf("Match: #%d Name: %q Relevance: %v Center: %#v\n", i, feat.PlaceName, feat.Relevance, feat.Center)
		for j, ctx := range feat.Context {
			fmt.Printf("\tContext: #%d:: %#v\n", j, ctx)
		}
		fmt.Printf("\n\n")
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var NoPathDuration = float32(-1)

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...Option) (*Client, error)

func (*Client) APIKey

func (c *Client) APIKey() string

func (*Client) APIVersion

func (c *Client) APIVersion() string

func (*Client) LookupLatLon

func (c *Client) LookupLatLon(ctx context.Context, lat, lon float64) (*GeocodeResponse, error)

LookupLatLon is a helper to reverse geocoding lookup a latitude and longitude pair.

func (*Client) LookupPlace

func (c *Client) LookupPlace(ctx context.Context, query string) (*GeocodeResponse, error)

LookupPlace looks up the coordinates and information of a place for example "Los Angeles" or "Edmonton".

func (*Client) RequestDuration

func (c *Client) RequestDuration(ctx context.Context, dreq *DurationRequest) (*DurationResponse, error)

func (*Client) ReverseGeocoding

func (c *Client) ReverseGeocoding(ctx context.Context, req *ReverseGeocodeRequest) (*GeocodeResponse, error)

ReverseGeocoding Converts coordinates to place names -77.036,38.897 -> 1600 Pennsylvania Ave NW.

func (*Client) SetAPIKey

func (c *Client) SetAPIKey(key string)

type DurationRequest

type DurationRequest struct {
	Coordinates []*LatLonPair `json:"coordinates"`
}

type DurationResponse

type DurationResponse struct {
	Durations []*LatLonPair `json:"durations,omitempty"`
}

type GeocodeContext

type GeocodeContext struct {
	Id        string `json:"id"`
	Text      string `json:"text"`
	ShortCode string `json:"short_code"`
	Wikidata  string `json:"wikidata"`
}

type GeocodeFeature

type GeocodeFeature struct {
	Id        string  `json:"id"`
	Type      string  `json:"type"`
	Text      string  `json:"text"`
	PlaceName string  `json:"place_name"`
	Relevance float32 `json:"relevance"`

	Properties *GeocodeProperty  `json:"properties"`
	Context    []*GeocodeContext `json:"context"`

	BoundingBox []float32 `json:"bbox"`
	Center      []float32 `json:"center"`
	Geometry    *Geometry `json:"geometry"`
	Attribution string    `json:"attribution"`
}

type GeocodeMode

type GeocodeMode string
const (
	GeocodePlaces          GeocodeMode = "mapbox.places"
	GeocodePermanentPlaces GeocodeMode = "mapbox.places-permanent"
)

func (GeocodeMode) String

func (gm GeocodeMode) String() string

type GeocodeProperty

type GeocodeProperty map[string]interface{}

type GeocodeRequest

type GeocodeRequest struct {
	// Country is a set of one or more countries
	// specified with ISO 3166 alpha 2 country codes.
	Country []string `json:"country,omitempty"`

	Limit uint          `json:"limit,omitempty"`
	Types []GeocodeType `json:"types,omitempty"`

	Proximity    *LatLonPair `json:"proximity,omitempty"`
	BoundingBox  []float32   `json:"bbox,omitempty"`
	AutoComplete bool        `json:"autocomplete,omitempty"`
}

type GeocodeResponse

type GeocodeResponse struct {
	Type     string            `json:"type,omitempty"`
	Query    *LatLonPair       `json:"query,omitempty"`
	Features []*GeocodeFeature `json:"features,omitempty"`
}

type GeocodeType

type GeocodeType string
const (
	GTypeRegion       GeocodeType = "region"
	GTypePostcode     GeocodeType = "postcode"
	GTypePlace        GeocodeType = "place"
	GTypeLocality     GeocodeType = "locality"
	GTypeNeighborhood GeocodeType = "neighborhood"
	GTypeAddress      GeocodeType = "address"
	GTypePOI          GeocodeType = "poi"
	GTypePOILandmark  GeocodeType = "poi.landmark"
)

type Geometry

type Geometry struct {
	Type        string    `json:"type"`
	Coordinates []float32 `json:"coordinates"`
}

type LatLonMatrix

type LatLonMatrix [][]float32

type LatLonPair

type LatLonPair []float32

func (*LatLonPair) UnmarshalJSON

func (llp *LatLonPair) UnmarshalJSON(b []byte) error

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

type ReverseGeocodeRequest

type ReverseGeocodeRequest struct {
	Query   string      `json:"query"`
	Mode    GeocodeMode `json:"mode"`
	Request *GeocodeRequest
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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