This commit is contained in:
suyl
2021-05-11 16:04:14 +08:00
parent 5c6f604d7d
commit bcebad3b41
2 changed files with 21 additions and 35 deletions

View File

@@ -69,39 +69,25 @@ func (a *API) GetCoordinateFromAddressByPage(address string, cityCode int) (lng,
} }
type GetCoordinateFromAddressByPageAllResult struct { type GetCoordinateFromAddressByPageAllResult struct {
Suggestion struct { ID string `json:"id"`
Keywords []interface{} `json:"keywords"` Parent []interface{} `json:"parent"`
Cities []interface{} `json:"cities"` Childtype []interface{} `json:"childtype"`
} `json:"suggestion"` Name string `json:"name"`
Count string `json:"count"` Type string `json:"type"`
Infocode string `json:"infocode"` Typecode string `json:"typecode"`
Pois []struct { BizType []interface{} `json:"biz_type"`
Parent []interface{} `json:"parent"` Address string `json:"address"`
Address string `json:"address"` Location string `json:"location"`
Distance []interface{} `json:"distance"` Tel []interface{} `json:"tel"`
Pname string `json:"pname"` Pname string `json:"pname"`
Importance []interface{} `json:"importance"` Cityname string `json:"cityname"`
BizExt struct { Adname string `json:"adname"`
Cost []interface{} `json:"cost"` Importance []interface{} `json:"importance"`
Rating []interface{} `json:"rating"` Shopid []interface{} `json:"shopid"`
} `json:"biz_ext"` Shopinfo string `json:"shopinfo"`
BizType []interface{} `json:"biz_type"` Poiweight []interface{} `json:"poiweight"`
Cityname string `json:"cityname"` Distance []interface{} `json:"distance"`
Type string `json:"type"` Photos []interface{} `json:"photos"`
Photos []interface{} `json:"photos"`
Typecode string `json:"typecode"`
Shopinfo string `json:"shopinfo"`
Poiweight []interface{} `json:"poiweight"`
Childtype []interface{} `json:"childtype"`
Adname string `json:"adname"`
Name string `json:"name"`
Location string `json:"location"`
Tel string `json:"tel"`
Shopid []interface{} `json:"shopid"`
ID string `json:"id"`
} `json:"pois"`
Status string `json:"status"`
Info string `json:"info"`
} }
func (a *API) GetCoordinateFromAddressByPageAll(address string, cityCode int) (getCoordinateFromAddressByPageAllResult *GetCoordinateFromAddressByPageAllResult, err error) { func (a *API) GetCoordinateFromAddressByPageAll(address string, cityCode int) (getCoordinateFromAddressByPageAllResult *GetCoordinateFromAddressByPageAllResult, err error) {
@@ -121,7 +107,7 @@ func (a *API) GetCoordinateFromAddressByPageAll(address string, cityCode int) (g
"children": "", "children": "",
}) })
if err == nil { if err == nil {
utils.Map2StructByJson(result, &getCoordinateFromAddressByPageAllResult, false) utils.Map2StructByJson(result["pois"].([]interface{})[0], &getCoordinateFromAddressByPageAllResult, false)
} }
return getCoordinateFromAddressByPageAllResult, err return getCoordinateFromAddressByPageAllResult, err
} }

View File

@@ -16,7 +16,7 @@ func TestGetCoordinateFromAddressByPage(t *testing.T) {
} }
func TestGetCoordinateFromAddressByPageAll(t *testing.T) { func TestGetCoordinateFromAddressByPageAll(t *testing.T) {
result, err := autonaviAPI.GetCoordinateFromAddressByPageAll("兴月宏干杂", 510100) result, err := autonaviAPI.GetCoordinateFromAddressByPageAll("重庆市南岸区南坪正街1号", 500100)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }