Пример #1
0
func TestReverseGeocodeFromNewGoogleGeocoder(t *testing.T) {
	geocoder := google.NewGeocoder()

	res, _ := geocoder.ReverseGeocode(47.6064, -122.330803)

	var address google.Address
	google.ReadResponse(res, &address)

	assert.Equal(t, "Seattle", address.City)
	assert.Equal(t, "WA", address.State)
	assert.Equal(t, "US", address.Country)
}
Пример #2
0
func TestReverseGeocodeForMSU(t *testing.T) {
	lat, lng := 42.72476, -84.473639

	geocoder := google.NewGeocoder()

	res, _ := geocoder.ReverseGeocode(lat, lng)

	var address google.Address
	google.ReadResponse(res, &address)

	assert.Equal(t, "East Lansing", address.City)
	assert.Equal(t, "MI", address.State)
	assert.Equal(t, "US", address.Country)
}
Пример #3
0
func TestReverseGeocodeFromGoogleCoder(t *testing.T) {
	geocoder := google.Geocoder{
		HttpClient:             &http.Client{},
		ReverseGeocodeEndpoint: "https://maps.googleapis.com/maps/api/geocode/json?latlng=%v,%v",
	}

	res, _ := geocoder.ReverseGeocode(47.6064, -122.330803)

	var address google.Address
	google.ReadResponse(res, &address)

	assert.Equal(t, "Seattle", address.City)
	assert.Equal(t, "WA", address.State)
	assert.Equal(t, "US", address.Country)
}
Пример #4
0
func fetchLatLngFromGoogle(trail Trail, context appengine.Context) []string {
	geoCoder := &google.Geocoder{
		HttpClient:             urlfetch.Client(context),
		ReverseGeocodeEndpoint: google.ReverseGeocodeEndpoint + "&key=AIzaSyC1O6FZtjFDSJz5zCqVbVlVOr60gDYg_Zw",
	}

	if (trail.GeoPoint == appengine.GeoPoint{}) {
		return []string{Uncategorized}
	}

	println(">>>>>>About to fetch from Google!")
	res, err := geoCoder.ReverseGeocode(trail.GeoPoint.Lat, trail.GeoPoint.Lng)
	if err != nil {
		return []string{Uncategorized}
	}

	var address google.Address
	google.ReadResponse(res, &address)

	return []string{address.FullCountry, address.FullState, address.FullCity}
}