Beispiel #1
0
// 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
}
Beispiel #2
0
// 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
}