1
This commit is contained in:
@@ -119,6 +119,10 @@ type API struct {
|
||||
key string
|
||||
}
|
||||
|
||||
func (a *API) SetKey(key string) {
|
||||
a.key = key
|
||||
}
|
||||
|
||||
type BuildingOrNeighborInfo struct {
|
||||
Name string `json:"name"`
|
||||
Type string `json:"type"`
|
||||
@@ -278,6 +282,35 @@ func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal Re
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI3(apiStr string, params map[string]interface{}) (retVal ResponseResult, err error) {
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
request, _ := http.NewRequest(http.MethodGet, utils.GenerateGetURL(BaseUrl, apiStr, params), nil)
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||
if jsonResult1 == nil {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
status := jsonResult1["status"].(string)
|
||||
if status == StatusCodeSuccess {
|
||||
retVal = jsonResult1
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
}
|
||||
infoCode := jsonResult1["infocode"].(string)
|
||||
newErr := utils.NewErrorCode(jsonResult1["info"].(string), infoCode)
|
||||
if _, ok := exceedLimitCodes[infoCode]; ok {
|
||||
return platformapi.ErrLevelExceedLimit, newErr
|
||||
} else if _, ok := canRetryCodes[infoCode]; ok {
|
||||
return platformapi.ErrLevelRecoverableErr, newErr
|
||||
} else {
|
||||
return platformapi.ErrLevelCodeIsNotOK, newErr
|
||||
}
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
func (a *API) BatchAccessAPI(apiList []*tBatchAPIParams) (retVal []*tBatchAPIResponse, err error) {
|
||||
if len(apiList) == 0 {
|
||||
return nil, nil
|
||||
|
||||
47
platformapi/autonavi/gaode_api.go
Normal file
47
platformapi/autonavi/gaode_api.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package autonavi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GetCyclingPlan 获取骑手的骑行计划
|
||||
func (a *API) GetCyclingPlan(origin, destination string) ([]string, int64, int64, error) {
|
||||
param := map[string]interface{}{
|
||||
"key": a.key,
|
||||
"origin": origin,
|
||||
"destination": destination,
|
||||
"show_fields": "polyline",
|
||||
}
|
||||
result, err := a.AccessAPI3("direction/electrobike", param)
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
var data *CyclingPlan
|
||||
if err := utils.Map2StructByJson(result, data, false); err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
|
||||
if data.Status != "1" && data.Info != "ok" {
|
||||
return nil, 0, 0, fmt.Errorf(data.Infocode)
|
||||
}
|
||||
|
||||
polyLineList := make([]string, 0, 0) // 坐标
|
||||
var distance int64 = 0 // 距离 4329
|
||||
var duration int64 = 0 // 时间 978
|
||||
for _, v := range data.Route.Paths {
|
||||
for _, v2 := range v.Steps {
|
||||
if v2.Polyline != "" {
|
||||
polyLine := strings.Split(v2.Polyline, ";")
|
||||
if polyLine != nil {
|
||||
polyLineList = append(polyLineList, polyLine...)
|
||||
}
|
||||
}
|
||||
}
|
||||
distance = utils.Str2Int64(v.Distance)
|
||||
duration = utils.Str2Int64(v.Duration) + 600
|
||||
}
|
||||
|
||||
return polyLineList, distance, duration, nil
|
||||
}
|
||||
22
platformapi/autonavi/gaode_const.go
Normal file
22
platformapi/autonavi/gaode_const.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package autonavi
|
||||
|
||||
// 高德骑行计划账号配置
|
||||
const (
|
||||
AMAPCyclingPlanKey1 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 成都若溪科技有限公司 18048531223 Rosy201507
|
||||
AMAPCyclingPlanKey2 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 成都京西到家网络科技有限公司 18080188338 Rosy201507
|
||||
AMAPCyclingPlanKey3 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 冲天猴儿(成都)科技有限公司 19802843833 Rosy201507
|
||||
AMAPCyclingPlanKey4 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 京西(成都)科技有限公司 18884789801 Rosy201507
|
||||
AMAPCyclingPlanKey5 = "e44ae2850c0ac930b65c9652d2db0321" // 高德地图 京西菜市(北京)科技有限公司 17723303721 Rosy201507
|
||||
)
|
||||
|
||||
// 错误码
|
||||
const (
|
||||
DAILYQUERYOVERLIMIT = "10003" // 访问已超出日访问量
|
||||
)
|
||||
|
||||
// BaseUrl 基础访问链接
|
||||
const BaseUrl = "https://restapi.amap.com/v5"
|
||||
|
||||
// 白名单
|
||||
//148.70.158.63
|
||||
//132.232.12.131
|
||||
29
platformapi/autonavi/gaode_model.go
Normal file
29
platformapi/autonavi/gaode_model.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package autonavi
|
||||
|
||||
type CyclingPlan struct {
|
||||
Status string `json:"status"` // 本次状态 1-成功 0-失败
|
||||
Info string `json:"info"` // 成功ok 失败错误码
|
||||
Infocode string `json:"infocode"` // 返回状态说明
|
||||
Count string `json:"count"` // 路径规划方案
|
||||
Route Route `json:"route"` // 方案列表
|
||||
}
|
||||
|
||||
type Route struct {
|
||||
Origin string `json:"origin"` // 起点经纬度
|
||||
Destination string `json:"destination"` // 终点经纬度
|
||||
Paths []Paths `json:"paths"` // 方案详情
|
||||
}
|
||||
|
||||
type Paths struct {
|
||||
Distance string `json:"distance"` // 距离:米
|
||||
Duration string `json:"duration"` // 线路耗时,包括方案总耗时及分段step中的耗时
|
||||
Steps []Steps `json:"steps"` // 路线分段
|
||||
}
|
||||
|
||||
type Steps struct {
|
||||
Instruction string `json:"instruction"` // 骑行指示
|
||||
Orientation string `json:"orientation"` // 进入道路方向
|
||||
RoadName string `json:"road_name"` // 分段道路名称
|
||||
StepDistance int `json:"step_distance"` // 分段距离信息
|
||||
Polyline string `json:"polyline"` // 设置后可返回分路段坐标点串,两点间用“,”分隔
|
||||
}
|
||||
17
platformapi/autonavi/gaode_test.go
Normal file
17
platformapi/autonavi/gaode_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package autonavi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetCyclingPlan(t *testing.T) {
|
||||
key := "e44ae2850c0ac930b65c9652d2db0321"
|
||||
a := New(key)
|
||||
a.GetCyclingPlan("113.854912,22.601450", "113.846355,22.625570")
|
||||
}
|
||||
|
||||
func TestLng(t *testing.T) {
|
||||
origin := fmt.Sprintf("%f,%f", 113.854912, 22.601450)
|
||||
fmt.Println(origin)
|
||||
}
|
||||
Reference in New Issue
Block a user