Created
January 19, 2018 15:14
-
-
Save bdharris08/08f6465626b16093e3a573d319e2dfc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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