Skip to content

Latest commit

 

History

History
107 lines (70 loc) · 2.77 KB

README.md

File metadata and controls

107 lines (70 loc) · 2.77 KB

go-mapbox

Mapbox API wrappers for Golang

Documentation GitHub tag Build Status

See here for other golang/mapbox projects.

Status

Very early WIP, pull requests and issues are most welcome. See lib/geocode/ or lib/directions/ for an example module to mimic.

Because Travis-CI does not expose the build environment to untrusted branches (ie. Pull Requests) tests have to be manually prompted by a repository admin then force merged. Don't panic when your local tests pass but travis fails with "Mapbox API token not found", we will manually run them as soon as possible. See issue #10 for more information.

Modules

  • Geocoding
  • Directions
  • Directions Matrix
  • Map Matching
  • Styles
  • Maps
  • Static
  • Datasets

Examples

Initialisation

// Import the core module (and any required APIs)
import (
    "gopkg.in/ryankurte/go-mapbox.v0/lib"
    "gopkg.in/ryankurte/go-mapbox.v0/lib/base"
)

// Fetch token from somewhere
token := os.Getenv("MAPBOX_TOKEN")

// Create new mapbox instance
mapBox := mapbox.NewMapbox(token)

Map API

import (
    "gopkg.in/ryankurte/go-mapbox.v0/lib/maps"
)

img, err := mapBox.Maps.GetTiles(maps.MapIDSatellite, 1, 0, 0, maps.MapFormatJpg90, true)

Geocoding

import (
    "gopkg.in/ryankurte/go-mapbox.v0/lib/geocode"
)

// Forward Geocoding
var forwardOpts geocode.ForwardRequestOpts
forwardOpts.Limit = 1

place := "2 lincoln memorial circle nw"

forward, err := mapBox.Geocode.Forward(place, &forwardOpts)


// Reverse Geocoding
var reverseOpts geocode.ReverseRequestOpts
reverseOpts.Limit = 1

loc := &base.Location{72.438939, 34.074122}

reverse, err := mapBox.Geocode.Reverse(loc, &reverseOpts)

Directions

import (
    "gopkg.in/ryankurte/go-mapbox.v0/lib/directions"
)

var directionOpts directions.RequestOpts

locs := []base.Location{{-122.42, 37.78}, {-77.03, 38.91}}

directions, err := mapBox.Directions.GetDirections(locs, directions.RoutingCycling, &directionOpts)

Layout


If you have any questions, comments, or suggestions, feel free to open an issue or a pull request.