Skip to content

Instantly share code, notes, and snippets.

@bdharris08
Created January 19, 2018 15:14
Show Gist options
  • Save bdharris08/08f6465626b16093e3a573d319e2dfc2 to your computer and use it in GitHub Desktop.
Save bdharris08/08f6465626b16093e3a573d319e2dfc2 to your computer and use it in GitHub Desktop.
func travelTime(from string, to string) Directions {
parameters := "json?origin=" + from + "&destination=" + to + "&key=" + key
options := "&departure_time=now"
api := "https://maps.googleapis.com/maps/api/directions/" + parameters + options
resp, err := http.Get(api)
check(err)
defer resp.Body.Close()
// body is a []Byte ("byte slice")
body, err := ioutil.ReadAll(resp.Body)
check(err)
// parse json (Unmarshal)
var d Directions
err = json.Unmarshal(body, &d)
check(err)
return d
}
// Directions is the top level return from google maps API
type Directions struct {
Routes []Route
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment