Example #1
0
func (loc Locntrl) CreateLoc(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	var re Request
	var r Response

	json.NewDecoder(r.Body).Decode(&re)
	coord := getLoc(re.Address + "+" + re.City + "+" + re.State + "+" + re.Zip)
	fmt.Println("Lat:", coord.Coordinate.Lat, "Long:", coord.Coordinate.Lang)

	r.Id = bson.NewObjectId()
	r.Add = re.Add
	r.City = re.City
	r.Name = re.Name
	r.Zip = re.Zip
	r.State = re.State
	r.Coordinate.Lang = coord.Coordinate.Lang
	r.Coordinate.Lat = coord.Coordinate.Lat
	loc.se.DB("jaspalgill").C("location").Insert(r)
	result, _ := json.Marshal(r)
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(201)
	fmt.Fprintf(w, "%s", result)
}