Git Product home page Git Product logo

geocoder's Introduction

Mapquest geocoder and directions for Go (golang)

What does it do

  • Returns a Longitude and Latitude for a given string query
  • Returns an address for a Longitude and Longitude
  • Returns directions between two or more points. (JSON or XML)

API Key

Get a free API Key at http://mapquestapi.com

Why MapQuest API?

Google Maps Geocoding API has a limitation that prohibits querying their geocoding API unless you will be displaying the results on a Google Map. Google directions is limited to 2 requests per second.

Install

  • go get "github.com/jasonwinn/geocoder"
  • import "github.com/jasonwinn/geocoder"

Examples

Set API Key

You'll want to set an api key for the Mapquest API to go into production.

// this is the testing key used in `go test`
SetAPIKey("Fmjtd%7Cluub256alu%2C7s%3Do5-9u82ur")

Geocode

  query := "Seattle WA"
  lat, lng, err := geocoder.Geocode(query)
  if err != nil {
    panic("THERE WAS SOME ERROR!!!!!")
  }
  
  // 47.6064, -122.330803
 

Reverse Geocode

  address, err := geocoder.ReverseGeocode(47.6064, -122.330803)
  if err != nil {
    panic("THERE WAS SOME ERROR!!!!!")
  }

  address.Street 	        // 542 Marion St   
  address.City 		        // Seattle
  address.State 	        // WA
  address.PostalCode 	    // 98104 
  address.County 	        // King
  address.CountryCode       // US 

Directions

  directions := NewDirections("Amsterdam,Netherlands", []string{"Antwerp,Belgium"})
  results, err := directions.Get()
  if err != nil {
    panic("THERE WAS SOME ERROR!!!!!")
  }

  route := results.Route
  time:= route.Time
  legs:= route.Legs
  distance:= route.Distance

  // or get distance with this shortcut
  //
  // use "k" to return result in km
  // use "m" to return result in miles
  distance, err := directions.Distance("k")
  if err != nil {
    panic("THERE WAS SOME ERROR!!!!!")
  }

Documentation

https://godoc.org/github.com/jasonwinn/geocoder

geocoder's People

Contributors

stanim avatar jasonwinn avatar cdipaolo avatar asmaloney avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.