当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.Geocode方法代码示例

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


在下文中一共展示了Client.Geocode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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


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