高德page

This commit is contained in:
苏尹岚
2020-09-21 10:16:10 +08:00
parent d7ff89c5e5
commit a37663d8ab
4 changed files with 83 additions and 3 deletions

View File

@@ -0,0 +1,64 @@
package autonavi
import (
"fmt"
"net/http"
"strings"
"git.rosy.net.cn/baseapi"
"git.rosy.net.cn/baseapi/platformapi"
"git.rosy.net.cn/baseapi/utils"
)
func (a *API) AccessStorePage(fullURL string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
err = platformapi.AccessPlatformAPIWithRetry(a.client,
func() *http.Request {
var request *http.Request
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(fullURL, "", bizParams), 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")
}
if strings.Contains(bodyStr, "登录") || strings.Contains(bodyStr, "访问的内容") {
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("cookie可能过期了")
}
if err == nil {
if jsonResult1["info"].(string) != "OK" {
errLevel = platformapi.ErrLevelGeneralFail
err = utils.NewErrorCode(jsonResult1["info"].(string), jsonResult1["infocode"].(string))
baseapi.SugarLogger.Debugf("autonavi_page AccessAPI failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
}
retVal = jsonResult1
}
return errLevel, err
})
return retVal, err
}
func (a *API) GetCoordinateFromAddressByPage(address string) (lng, lat float64, err error) {
result, err := a.AccessStorePage("https://restapi.amap.com/v3/place/text", map[string]interface{}{
"s": "rsv3",
"key": "8325164e247e15eea68b59e89200988b",
"page": 1,
"offset": 10,
"city": 510100,
"language": "zh_cn",
"platform": "JS",
"logversion": 2.0,
"sdkversion": 1.3,
"appname": "https://lbs.amap.com/console/show/picker",
"csid": "170EFB02-7F7C-4F47-A1D5-47E98DC17ABB",
"keywords": address,
})
if err == nil {
str := result["pois"].([]interface{})[0].(map[string]interface{})["location"].(string)
strs := strings.Split(str, ",")
if len(strs) > 0 {
return utils.Str2Float64(strs[0]), utils.Str2Float64(strs[1]), err
}
}
return lng, lat, err
}

View File

@@ -0,0 +1,16 @@
package autonavi
import (
"testing"
"git.rosy.net.cn/baseapi/utils"
)
func TestGetCoordinateFromAddressByPage(t *testing.T) {
lng, lat, err := autonaviAPI.GetCoordinateFromAddressByPage("广东深圳市龙华区观澜街道观澜社会福利中心1340号")
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(lng, false))
t.Log(utils.Format4Output(lat, false))
}

View File

@@ -85,7 +85,7 @@ func TestGetDistricts(t *testing.T) {
}
func TestGetCoordinateFromAddress(t *testing.T) {
lng, lat, districtCode := autonaviAPI.GetCoordinateFromAddress("四川省成都市锦江区城区复地金融岛湾流汇公寓", "")
lng, lat, districtCode := autonaviAPI.GetCoordinateFromAddress("广东深圳市龙华区观澜街道观澜社会福利中心1340号", "深圳市")
t.Logf("lng:%f, lat:%f, districtCode:%d", lng, lat, districtCode)
}

View File

@@ -68,14 +68,14 @@ func TestQueryOrderInfoByDate(t *testing.T) {
}
func TestDelPrinterSqs(t *testing.T) {
err := api.DelPrinterSqs("218510310")
err := api.DelPrinterSqs("220502420")
if err != nil {
t.Fatalf("DelPrinterSqs return error:%v", err)
}
}
func TestQueryPrinterStatus(t *testing.T) {
status, err := api.QueryPrinterStatus("550518714")
status, err := api.QueryPrinterStatus("220502420")
if err != nil {
t.Fatalf("QueryPrinterStatus return error:%v", err)
}