• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang maps.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cdupuis/strava/activity-namer/Godeps/_workspace/src/googlemaps/github/io/maps.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Client类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

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)
}
开发者ID:cdupuis,项目名称:strava,代码行数:31,代码来源:main.go


示例2: main

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)
}
开发者ID:cdupuis,项目名称:strava,代码行数:28,代码来源:queryautocomplete.go


示例3: main

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)
}
开发者ID:cdupuis,项目名称:strava,代码行数:29,代码来源:main.go


示例4: main

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)
}
开发者ID:cdupuis,项目名称:strava,代码行数:29,代码来源:textsearch.go


示例5: main

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)
}
开发者ID:cdupuis,项目名称:strava,代码行数:39,代码来源:main.go


示例6: main

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)
	}
}
开发者ID:cdupuis,项目名称:strava,代码行数:38,代码来源:photo.go


示例7: main

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)
}
开发者ID:cdupuis,项目名称:strava,代码行数:38,代码来源:main.go


示例8: geocode

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
}
开发者ID:cdupuis,项目名称:strava,代码行数:23,代码来源:main.go


示例9: main

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)
}
开发者ID:cdupuis,项目名称:strava,代码行数:23,代码来源:placedetails.go


示例10: main

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)
			}
		}
	}
}
开发者ID:cdupuis,项目名称:strava,代码行数:93,代码来源:main.go



注:本文中的github.com/cdupuis/strava/activity-namer/Godeps/_workspace/src/googlemaps/github/io/maps.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang backoff.NewExponentialBackOff函数代码示例发布时间:2022-05-23
下一篇:
Golang base.NormalizePoint函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap