1
This commit is contained in:
@@ -37,6 +37,9 @@ const (
|
||||
CoordSysWGS84 = 1 // GPS设备获取的角度坐标,WGS84坐标
|
||||
CoordSysGCJ02 = 3 // google地图、soso地图、aliyun地图、mapabc地图和amap地图所用坐标,国测局(GCJ02)坐标
|
||||
CoordSysBaiDu = 5 // 百度地图采用的经纬度坐标
|
||||
|
||||
CoordSysGaoDe2Baidu = "1" // 高德坐标转百度坐标
|
||||
CoordSysBaidu2Gaode = "5" // 百度坐标转高德坐标
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -160,7 +163,7 @@ func genGetURL(baseURL, apiStr string, params map[string]interface{}) string {
|
||||
return baseURL + queryString
|
||||
}
|
||||
|
||||
func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal interface{}, err error) {
|
||||
/*func (a *API) AccessAPI(apiStr string, params map[string]interface{}) (retVal interface{}, err error) {
|
||||
apiStr += "/"
|
||||
params2 := utils.MergeMaps(utils.Params2Map("ak", a.ak, "output", "json"), params)
|
||||
params2[signKey] = a.signParams(apiStr, params2)
|
||||
@@ -191,52 +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
|
||||
}
|
||||
var coordsStrList []string
|
||||
for _, v := range coords {
|
||||
coordsStrList = append(coordsStrList, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat))
|
||||
}
|
||||
|
||||
params := url.Values{
|
||||
"coords": []string{strings.Join(coordsStrList, ";")},
|
||||
"from": []string{utils.Int2Str(fromCoordSys)},
|
||||
"to": []string{utils.Int2Str(toCoordSys)},
|
||||
}
|
||||
|
||||
result, err := a.AccessAPI2("geoconv/v1/", params)
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(result[resultKey], &outCoords, false)
|
||||
}
|
||||
return outCoords, err
|
||||
}
|
||||
|
||||
func (a *API) DirectionLiteRide(coords []*Coordinate) (retVal interface{}, err error) {
|
||||
var (
|
||||
sCoords string
|
||||
uCoords string
|
||||
apiStr = "directionlite/v1/riding"
|
||||
)
|
||||
sCoords = utils.Float64ToStr(coords[0].Lat) + "," + utils.Float64ToStr(coords[0].Lng)
|
||||
uCoords = utils.Float64ToStr(coords[1].Lat) + "," + utils.Float64ToStr(coords[1].Lng)
|
||||
|
||||
param := url.Values{
|
||||
"origin": []string{sCoords},
|
||||
"destination": []string{uCoords},
|
||||
}
|
||||
|
||||
resp, err := a.AccessAPI2(apiStr, param)
|
||||
if err == nil {
|
||||
return resp[resultKey], nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
}*/
|
||||
|
||||
func (a *API) AccessAPI2(apiStr string, param url.Values) (retVal map[string]interface{}, err error) {
|
||||
|
||||
@@ -259,15 +217,10 @@ func (a *API) AccessAPI2(apiStr string, param url.Values) (retVal map[string]int
|
||||
}
|
||||
|
||||
resp, err1 := http.Get(request.String())
|
||||
//err1 = errors.New("测试退出退出")
|
||||
//defer resp.Body.Close()
|
||||
body, err2 := ioutil.ReadAll(resp.Body)
|
||||
if err1 != nil || err2 != nil {
|
||||
continue
|
||||
}
|
||||
//result := string(body)
|
||||
//result := map[string]interface{}{}
|
||||
|
||||
err = json.Unmarshal(body, &retVal)
|
||||
if err == nil {
|
||||
return retVal, nil
|
||||
@@ -275,3 +228,84 @@ func (a *API) AccessAPI2(apiStr string, param url.Values) (retVal map[string]int
|
||||
}
|
||||
return nil, errors.New("所有百度应用额度均用完")
|
||||
}
|
||||
|
||||
// BatchCoordinateConvert 坐标转换
|
||||
//func (a *API) BatchCoordinateConvert(coords []*Coordinate, fromCoordSys, toCoordSys int) (outCoords []*Coordinate, err error) {
|
||||
// if fromCoordSys == toCoordSys {
|
||||
// return coords, nil
|
||||
// }
|
||||
// var coordsStrList []string
|
||||
// for _, v := range coords {
|
||||
// coordsStrList = append(coordsStrList, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat))
|
||||
// }
|
||||
//
|
||||
// params := url.Values{
|
||||
// "coords": []string{strings.Join(coordsStrList, ";")},
|
||||
// "from": []string{utils.Int2Str(fromCoordSys)},
|
||||
// "to": []string{utils.Int2Str(toCoordSys)},
|
||||
// }
|
||||
//
|
||||
// result, err := a.AccessAPI2("geoconv/v1/", params)
|
||||
// if err == nil {
|
||||
// err = utils.Map2StructByJson(result[resultKey], &outCoords, false)
|
||||
// }
|
||||
// return outCoords, err
|
||||
//}
|
||||
|
||||
// BatchCoordinateConvert 坐标转换
|
||||
func (a *API) BatchCoordinateConvert(coords []*Coordinate, changeType string) (outCoords []*Coordinate, err error) {
|
||||
var coordsStrList []string
|
||||
for _, v := range coords {
|
||||
coordsStrList = append(coordsStrList, fmt.Sprintf("%.6f,%.6f", v.Lng, v.Lat))
|
||||
}
|
||||
|
||||
params := url.Values{
|
||||
"coords": []string{strings.Join(coordsStrList, ";")},
|
||||
"model": []string{changeType}, // 1:高德转百度 5:百度转高德
|
||||
//"from": []string{utils.Int2Str(fromCoordSys)},
|
||||
//"to": []string{utils.Int2Str(toCoordSys)},
|
||||
}
|
||||
|
||||
result, err := a.AccessAPI2("geoconv/v2/", params)
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(result[resultKey], &outCoords, false)
|
||||
}
|
||||
return outCoords, err
|
||||
}
|
||||
|
||||
// BatchCoordinateConvertBai2Gao 百度转高德
|
||||
func (a *API) BatchCoordinateConvertBai2Gao(coords []string, changeType string) (outCoords []*Coordinate, err error) {
|
||||
params := url.Values{
|
||||
"coords": []string{strings.Join(coords, ";")},
|
||||
"model": []string{changeType}, // 1:高德转百度 5:百度转高德
|
||||
}
|
||||
|
||||
result, err := a.AccessAPI2("geoconv/v2/", params)
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(result[resultKey], &outCoords, false)
|
||||
}
|
||||
return outCoords, err
|
||||
}
|
||||
|
||||
// DirectionLiteRide 获取骑行距离
|
||||
func (a *API) DirectionLiteRide(coords []*Coordinate) (retVal interface{}, err error) {
|
||||
var (
|
||||
sCoords string
|
||||
uCoords string
|
||||
apiStr = "directionlite/v1/riding"
|
||||
)
|
||||
sCoords = utils.Float64ToStr(coords[0].Lat) + "," + utils.Float64ToStr(coords[0].Lng)
|
||||
uCoords = utils.Float64ToStr(coords[1].Lat) + "," + utils.Float64ToStr(coords[1].Lng)
|
||||
|
||||
param := url.Values{
|
||||
"origin": []string{sCoords},
|
||||
"destination": []string{uCoords},
|
||||
}
|
||||
|
||||
resp, err := a.AccessAPI2(apiStr, param)
|
||||
if err == nil {
|
||||
return resp[resultKey], nil
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -26,16 +26,13 @@ func init() {
|
||||
}
|
||||
|
||||
func TestBatchCoordinateConvert(t *testing.T) {
|
||||
//result, err := api.BatchCoordinateConvert([]*Coordinate{
|
||||
result, err := api.BatchCoordinateConvert([]*Coordinate{
|
||||
&Coordinate{
|
||||
Lng: 104.057367,
|
||||
Lat: 30.694686,
|
||||
Lng: 104.00701626019786,
|
||||
Lat: 30.660569196450925,
|
||||
},
|
||||
&Coordinate{
|
||||
Lng: 104.057367,
|
||||
Lat: 30.694686,
|
||||
},
|
||||
}, CoordSysGCJ02, CoordSysBaiDu)
|
||||
}, "5")
|
||||
if err != nil {
|
||||
t.Fatalf("TestCoordinateConvert failed with error:%v", err)
|
||||
} else {
|
||||
@@ -59,6 +56,16 @@ func TestDirectionLiteRide(t *testing.T) {
|
||||
fmt.Println(result)
|
||||
|
||||
}
|
||||
func TestAC(t *testing.T) {
|
||||
fmt.Println(fmt.Sprintf("%.6f,%.6f", 104.00080006826988, 30.65440926211375))
|
||||
}
|
||||
|
||||
func TestBatchCoordinateConvertBai2Gao(t *testing.T) {
|
||||
aa := []string{"104.00703948726,30.66023262214", "104.00734814129,30.660267081943"}
|
||||
result, err := api.BatchCoordinateConvertBai2Gao(aa, "5")
|
||||
fmt.Println(err)
|
||||
fmt.Println(result)
|
||||
}
|
||||
|
||||
func TestName(t *testing.T) {
|
||||
syncStatus := 1
|
||||
|
||||
@@ -236,7 +236,7 @@ func TestBatchSetPrice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetailDelete(t *testing.T) {
|
||||
poiCode := "18877719"
|
||||
poiCode := "17088914"
|
||||
|
||||
i := 0
|
||||
count := 0
|
||||
@@ -453,9 +453,9 @@ func TestRetailSkuSellStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRetailSellStatus(t *testing.T) {
|
||||
result, err := api.RetailSellStatus(utils.GetUUID(), "10071426", []*BareStoreFoodInfo{
|
||||
result, err := api.RetailSellStatus(utils.GetUUID(), "17088914", []*BareStoreFoodInfo{
|
||||
&BareStoreFoodInfo{
|
||||
AppFoodCode: "6092651",
|
||||
AppFoodCode: "2429611",
|
||||
Skus: []*BareStoreSkuInfo{
|
||||
&BareStoreSkuInfo{
|
||||
//SkuID: "22781",
|
||||
|
||||
Reference in New Issue
Block a user