Trajectory.go 1014 Bytes
package Api

import (
	"encoding/json"
	"github.com/aarongao/tools"
	"github.com/gin-gonic/gin"
	"letu/DB"
	"time"
)

// @Title 保存用户移动轨迹
// @Description 保存用户移动轨迹
// @Accept  json
// @Produce  json
// @Param   UserId     5dfb03070a9ac17ac7a82054    string     true        "用户id"
// @Param   Location     {"Latitude": 119, "Longitude": 39}    string     true  	"经纬度"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /Trajectory/Save? [post]
func SaveTrajectory(c *gin.Context) {
	c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
	c.Header("Access-Control-Allow-Credentials", "true")

	var Location DB.SLocation
	json.Unmarshal([]byte(c.PostForm("Location")), &Location)

	DB.CTrajectory.Insert(DB.STrajectory{
		c.PostForm("UserId"),
		Location,
		time.Now().Unix(),
	})

	c.JSON(200, tools.ResponseSeccess{
		0,
		"ok",
	})
}