From d26e0e540616bfa202aaf4bb039c5f77dbf35dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Mon, 11 Sep 2023 14:55:40 +0800 Subject: [PATCH] 1 --- platformapi/autonavi/gaode_const.go | 3 +- platformapi/baidunavi/baidunavi.go | 18 ++++-- platformapi/baidunavi/baidunavi_model.go | 73 ++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 platformapi/baidunavi/baidunavi_model.go diff --git a/platformapi/autonavi/gaode_const.go b/platformapi/autonavi/gaode_const.go index ee02fb40..e3f72eb2 100644 --- a/platformapi/autonavi/gaode_const.go +++ b/platformapi/autonavi/gaode_const.go @@ -11,7 +11,8 @@ const ( // 错误码 const ( - DAILYQUERYOVERLIMIT = "10003" // 访问已超出日访问量 + DAILYQUERYOVERLIMIT = "10003" // 访问已超出日访问量 + USERDAILYQUERYOVERLIMIT = "10044" // 账号纬度的超出日访问量 ) // BaseUrl 基础访问链接 diff --git a/platformapi/baidunavi/baidunavi.go b/platformapi/baidunavi/baidunavi.go index 6d8424fb..29966bb8 100644 --- a/platformapi/baidunavi/baidunavi.go +++ b/platformapi/baidunavi/baidunavi.go @@ -2,7 +2,9 @@ package baidunavi import ( "crypto/md5" + "encoding/json" "fmt" + "git.rosy.net.cn/jx-callback/globals" "io/ioutil" "net/http" "net/url" @@ -192,6 +194,7 @@ func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal in return retVal, err } +// BatchCoordinateConvert 坐标转换 func (a *API) BatchCoordinateConvert(coords []*Coordinate, fromCoordSys, toCoordSys int) (outCoords []*Coordinate, err error) { if fromCoordSys == toCoordSys { return coords, nil @@ -244,22 +247,25 @@ func (a *API) DirectionLiteRide(coords []*Coordinate) (retVal interface{}, err e // 发起请求 request, err := url.Parse(prodURL2 + "/" + apiStr + "?" + params.Encode()) if nil != err { - fmt.Printf("host error: %v", err) - return + return nil, err } resp, err1 := http.Get(request.String()) - fmt.Printf("url: %s\n", request.String()) defer resp.Body.Close() if err1 != nil { - fmt.Printf("request error: %v", err1) - return + return nil, err1 } body, err2 := ioutil.ReadAll(resp.Body) if err2 != nil { - fmt.Printf("response error: %v", err2) + return nil, err2 } result := string(body) + path := &RiderPath{} + if err := json.Unmarshal([]byte(result), path); err != nil { + return result, nil + } + globals.SugarLogger.Debugf("=======path := %s", utils.Format4Output(path, false)) + return result, nil } diff --git a/platformapi/baidunavi/baidunavi_model.go b/platformapi/baidunavi/baidunavi_model.go new file mode 100644 index 00000000..5df28e53 --- /dev/null +++ b/platformapi/baidunavi/baidunavi_model.go @@ -0,0 +1,73 @@ +package baidunavi + +// RiderPath 骑行路线 +//type RiderPath struct { +// Status int `json:"status"` // 状态码 0-成功,1-服务器内部错误,2-参数无效,7-无结果返回 +// Message string `json:"message"` // 状态码对应的信息 +// Result struct { +// RiderResult +// Routes []struct { +// Distance int `json:"distance"` // 距离米 +// Duration int `json:"duration"` // 时间秒 +// Steps []struct { +// Distance int `json:"distance"` +// Duration int `json:"duration"` +// Direction int `json:"direction"` +// TurnType string `json:"turn_type"` +// Name string `json:"name"` +// Instruction string `json:"instruction"` +// RestrictionsInfo string `json:"restrictions_info"` +// Path string `json:"path"` +// StartLocation RiderCoordinate `json:"start_location"` +// EndLocation RiderCoordinate `json:"end_location"` +// } `json:"steps"` +// } `json:"routes"` +// } `json:"result"` +//} +// +//type RiderResult struct { +// Origin RiderCoordinate `json:"origin"` // 起点经纬度 +// Destination RiderCoordinate `json:"destination"` // 终点经纬度 +//} +// +//type RiderCoordinate struct { +// Lng float64 `json:"lng"` // 经度 +// Lat float64 `json:"lat"` // 纬度 +//} + +type RiderPath struct { + Status int `json:"status"` + Message string `json:"message"` + Result struct { + Origin struct { + Lng float64 `json:"lng"` + Lat float64 `json:"lat"` + } `json:"origin"` + Destination struct { + Lng float64 `json:"lng"` + Lat float64 `json:"lat"` + } `json:"destination"` + Routes []struct { + Distance int `json:"distance"` + Duration int `json:"duration"` + Steps []struct { + Distance int `json:"distance"` + Duration int `json:"duration"` + Direction int `json:"direction"` + TurnType string `json:"turn_type"` + Name string `json:"name"` + Instruction string `json:"instruction"` + RestrictionsInfo string `json:"restrictions_info"` + Path string `json:"path"` + StartLocation struct { + Lng string `json:"lng"` + Lat string `json:"lat"` + } `json:"start_location"` + EndLocation struct { + Lng string `json:"lng"` + Lat string `json:"lat"` + } `json:"end_location"` + } `json:"steps"` + } `json:"routes"` + } `json:"result"` +}