コード例 #1
0
ファイル: main.go プロジェクト: Rompei/habomaijiro-backend
func getPlace(tweets []Tweet) (err error) {
	runtime.GOMAXPROCS(runtime.NumCPU())
	var wg sync.WaitGroup
	service := places.NewService(http.DefaultClient, os.Getenv("PLACE_API_KEY"))
	for i := range tweets {
		wg.Add(1)
		go sendSearch(service, &tweets[i], &wg)
	}
	wg.Wait()
	return
}
コード例 #2
0
func main() {
	key := flag.String("key", "", "google places api key")
	flag.Parse()

	service := places.NewService(http.DefaultClient, *key)

	call := service.Nearby(37.7833, -122.4167) // San Francisco
	call.Types = append(call.Types, places.Cafe)
	call.Radius = 500

	resp, err := call.Do()
	if places.IsZeroResults(err) {
		fmt.Println("no results")
		return
	}
	if err != nil {
		panic(err)
	}

	results := resp.Results
	token := resp.NextPageToken

	for token != "" {
		time.Sleep(0 * time.Second) // Rate limit

		call.PageToken = token
		resp, err := call.Do()
		if err != nil {
			panic(err)
		}

		token = resp.NextPageToken
		results = append(results, resp.Results...)
	}

	for _, result := range results {
		fmt.Println(result.Name)
	}
}
コード例 #3
0
func main() {
	key := flag.String("key", "", "google places api key")
	flag.Parse()

	service := places.NewService(http.DefaultClient, *key)

	call := service.TextSearch("Google")

	resp, err := call.Do()
	if places.IsZeroResults(err) {
		fmt.Println("no results")
		return
	}
	if err != nil {
		panic(err)
	}

	results := resp.Results
	token := resp.NextPageToken

	for token != "" {
		time.Sleep(2 * time.Second) // Rate limit

		call.PageToken = token
		resp, err := call.Do()
		if err != nil {
			panic(err)
		}

		token = resp.NextPageToken
		results = append(results, resp.Results...)
	}

	for _, result := range results {
		fmt.Println(result.Name)
	}
}