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)

	r := &maps.TextSearchRequest{
		Query:    *query,
		Language: *language,
		Radius:   *radius,
		OpenNow:  *opennow,
	}

	parseLocation(*location, r)
	parsePriceLevels(*minprice, *maxprice, r)
	parsePlaceType(*placeType, 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.NearbySearchRequest{
		Radius:    *radius,
		Keyword:   *keyword,
		Language:  *language,
		Name:      *name,
		OpenNow:   *openNow,
		PageToken: *pageToken,
	}

	parseLocation(*location, r)
	parsePriceLevels(*minPrice, *maxPrice, r)
	parseRankBy(*rankBy, r)
	parsePlaceType(*placeType, r)

	resp, err := client.NearbySearch(context.Background(), r)
	check(err)

	pretty.Println(resp)
}
Beispiel #4
0
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)
}
Beispiel #5
0
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)
}
Beispiel #6
0
func geocodeBuildings(c *maps.Client) error {
	buildings, err := models.LoadMapData()
	if err != nil {
		return err
	}
	for _, b := range buildings {
		if b.Position != nil || len(b.Address) == 0 {
			continue
		}
		log.Printf("geocoding %s", b.Name)
		req := &maps.GeocodingRequest{
			Address: b.Address,
			Region:  "ca",
		}
		result, err := c.Geocode(context.TODO(), req)
		if err != nil {
			return err
		}
		if len(result) == 0 {
			continue
		}
		loc := result[0].Geometry.Location
		b.Position = &models.LatLng{
			Lat: loc.Lat,
			Lng: loc.Lng,
		}
		time.Sleep(100 * time.Millisecond)
		if err := models.SaveMapData(buildings); err != nil {
			return err
		}
	}
	for _, b := range buildings {
		if len(b.Floors) == 0 {
			continue
		}
		var lat, lng float64
		c := float64(len(b.Floors) * 2)
		for _, f := range b.Floors {
			lat += f.Coords.North
			lat += f.Coords.South
			lng += f.Coords.West
			lng += f.Coords.East
			for _, r := range f.Rooms {
				lat += r.Position.Lat
				lng += r.Position.Lng
				c += 1
			}
		}
		b.Position.Lat = lat / c
		b.Position.Lng = lng / c
	}
	return models.SaveMapData(buildings)
}
Beispiel #7
0
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)
}
Beispiel #8
0
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 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.RadarSearchRequest{
		Radius:  *radius,
		Keyword: *keyword,
		Name:    *name,
		OpenNow: *opennow,
	}

	parseLocation(*location, r)
	parsePriceLevels(*minprice, *maxprice, r)
	parsePlaceType(*placeType, r)

	resp, err := client.RadarSearch(context.Background(), r)
	check(err)

	for i, result := range resp.Results {
		r2 := &maps.PlaceDetailsRequest{
			PlaceID: result.PlaceID,
		}
		resp, err := client.PlaceDetails(context.Background(), r2)
		check(err)

		fmt.Printf("%d: %v at %v\n", i, resp.Name, resp.FormattedAddress)
	}
}
Beispiel #10
0
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)
	}
}
Beispiel #11
0
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)
}
Beispiel #12
0
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)
			}
		}
	}
}