コード例 #1
0
ファイル: city.go プロジェクト: pwambach/refugeemaps
// Get the city according to subdomain or position from the request
func Get(r *http.Request) (city City) {
	c := appengine.NewContext(r)

	cities := load(c)
	calledSubdomain := subdomain.GetFromRequest(r)
	userPosition := position.GetFromRequest(r)

	if calledSubdomain != "" {
		city = selectByID(cities, calledSubdomain)
	}

	if city.ID == "" && userPosition.Lat != 0 && userPosition.Lng != 0 {
		city = selectClosest(c, cities, userPosition)
	}

	if city.ID == "" {
		city = cities[0]
	}

	return
}
コード例 #2
0
ファイル: locations.go プロジェクト: refugeemaps/refugeemaps
// Get the location according to subdomain or position from the request
func Get(r *http.Request) (location Location) {
	c := appengine.NewContext(r)

	locations := All(c)
	calledSubdomain := subdomain.GetFromRequest(r)
	userPosition := position.GetFromRequest(r)

	if calledSubdomain != "" {
		location = selectByID(locations, calledSubdomain)
	}

	if location.ID == "" && userPosition.Lat != 0 && userPosition.Lng != 0 {
		location = selectClosest(c, locations, userPosition)
	}

	if location.ID == "" {
		location = locations[0]
	}

	return
}