func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) r := &maps.GeocodingRequest{ Address: *address, Language: *language, Region: *region, } parseComponents(*components, r) parseBounds(*bounds, r) parseLatLng(*latlng, r) parseResultType(*resultType, r) parseLocationType(*locationType, r) resp, err := client.Geocode(context.Background(), r) check(err) pretty.Println(resp) }
func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) r := &maps.QueryAutocompleteRequest{ Input: *input, Language: *language, Radius: *radius, Offset: *offset, } parseLocation(*location, r) resp, err := client.QueryAutocomplete(context.Background(), r) check(err) pretty.Println(resp) }
func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) t, err := strconv.Atoi(*timestamp) check(err) r := &maps.TimezoneRequest{ Language: *language, Timestamp: time.Unix(int64(t), 0), } parseLocation(*location, r) resp, err := client.Timezone(context.Background(), r) check(err) pretty.Println(resp) }
func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) r := &maps.TextSearchRequest{ Query: *query, Language: *language, Radius: *radius, OpenNow: *opennow, } parseLocation(*location, r) parsePriceLevels(*minprice, *maxprice, r) resp, err := client.TextSearch(context.Background(), r) check(err) pretty.Println(resp) }
func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) r := &maps.ElevationRequest{} if *samples > 0 { r.Samples = *samples } if *locations != "" { l, err := decodeLocations(*locations) check(err) r.Locations = l } if *path != "" { p, err := decodePath(*path) check(err) r.Path = p } resp, err := client.Elevation(context.Background(), r) if err != nil { log.Fatalf("Could not request elevations: %v", err) } pretty.Println(resp) }
func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) r := &maps.PlacePhotoRequest{ PhotoReference: *photoreference, MaxHeight: uint(*maxheight), MaxWidth: uint(*maxwidth), } resp, err := client.PlacePhoto(context.Background(), r) check(err) log.Printf("Content-Type: %v\n", resp.ContentType) img, err := resp.Image() check(err) log.Printf("Image bounds: %v", img.Bounds()) if *basename != "" { filename := fmt.Sprintf("%s.%s", *basename, "jpg") f, err := os.Create(filename) check(err) err = jpeg.Encode(f, img, &jpeg.Options{Quality: 85}) check(err) log.Printf("Wrote image to %s\n", filename) } }
func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) r := &maps.DistanceMatrixRequest{ Language: *language, DepartureTime: *departureTime, ArrivalTime: *arrivalTime, } if *origins != "" { r.Origins = strings.Split(*origins, "|") } if *destinations != "" { r.Destinations = strings.Split(*destinations, "|") } lookupMode(*mode, r) lookupAvoid(*avoid, r) lookupUnits(*units, r) lookupTransitMode(*transitMode, r) lookupTransitRoutingPreference(*transitRoutingPreference, r) resp, err := client.DistanceMatrix(context.Background(), r) check(err) pretty.Println(resp) }
func geocode(mapsClient *maps.Client, lat float64, lng float64) (string, string) { r := &maps.GeocodingRequest{ LatLng: &maps.LatLng{Lat: lat, Lng: lng}, } resp, err := mapsClient.Geocode(context.Background(), r) if err != nil { fmt.Println(err) os.Exit(1) } var city, country string for _, b := range resp[0].AddressComponents { if stringInSlice("country", b.Types) { country = b.LongName } if stringInSlice("locality", b.Types) { city = b.LongName } } return city, country }
func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) r := &maps.PlaceDetailsRequest{ PlaceID: *placeID, } resp, err := client.PlaceDetails(context.Background(), r) check(err) pretty.Println(resp) }
func main() { flag.Parse() var client *maps.Client var err error if *apiKey != "" { client, err = maps.NewClient(maps.WithAPIKey(*apiKey), maps.WithRateLimit(2)) } else if *clientID != "" || *signature != "" { client, err = maps.NewClient(maps.WithClientIDAndSignature(*clientID, *signature)) } else { usageAndExit("Please specify an API Key, or Client ID and Signature.") } check(err) r := &maps.DirectionsRequest{ Origin: *origin, Destination: *destination, DepartureTime: *departureTime, ArrivalTime: *arrivalTime, Alternatives: *alternatives, Language: *language, Region: *region, } lookupMode(*mode, r) lookupUnits(*units, r) lookupTransitRoutingPreference(*transitRoutingPreference, r) lookupTrafficModel(*trafficModel, r) if *waypoints != "" { r.Waypoints = strings.Split(*waypoints, "|") } if *avoid != "" { for _, a := range strings.Split(*avoid, "|") { switch a { case "tolls": r.Avoid = append(r.Avoid, maps.AvoidTolls) case "highways": r.Avoid = append(r.Avoid, maps.AvoidHighways) case "ferries": r.Avoid = append(r.Avoid, maps.AvoidFerries) default: log.Fatalf("Unknown avoid restriction %s", a) } } } if *transitMode != "" { for _, t := range strings.Split(*transitMode, "|") { switch t { case "bus": r.TransitMode = append(r.TransitMode, maps.TransitModeBus) case "subway": r.TransitMode = append(r.TransitMode, maps.TransitModeSubway) case "train": r.TransitMode = append(r.TransitMode, maps.TransitModeTrain) case "tram": r.TransitMode = append(r.TransitMode, maps.TransitModeTram) case "rail": r.TransitMode = append(r.TransitMode, maps.TransitModeRail) } } } if *iterations == 1 { routes, waypoints, err := client.Directions(context.Background(), r) check(err) pretty.Println(waypoints) pretty.Println(routes) } else { done := make(chan iterationResult) for i := 0; i < *iterations; i++ { go func(i int) { startTime := time.Now() _, _, err := client.Directions(context.Background(), r) done <- iterationResult{ fmt.Sprintf("Iteration %2d: round trip %.2f seconds", i, float64(time.Now().Sub(startTime))/1000000000), err, } }(i) } for i := 0; i < *iterations; i++ { result := <-done if err != nil { fmt.Printf("error: %+v\n", result.err) } else { fmt.Println(result.result) } } } }