This commit is contained in:
suyl
2021-05-11 16:13:37 +08:00
parent 706167fad2
commit 4d08df34f0

View File

@@ -69,28 +69,14 @@ func (a *API) GetCoordinateFromAddressByPage(address string, cityCode int) (lng,
} }
type GetCoordinateFromAddressByPageAllResult struct { type GetCoordinateFromAddressByPageAllResult struct {
ID string `json:"id"` Lng float64 `json:"lng"`
Parent []interface{} `json:"parent"` Lat float64 `json:"lat"`
Childtype []interface{} `json:"childtype"` AdName string `json:"adName"`
Name string `json:"name"` CityName string `json:"cityName"`
Type string `json:"type"`
Typecode string `json:"typecode"`
BizType []interface{} `json:"biz_type"`
Address string `json:"address"`
Location string `json:"location"`
Tel []interface{} `json:"tel"`
Pname string `json:"pname"`
Cityname string `json:"cityname"`
Adname string `json:"adname"`
Importance []interface{} `json:"importance"`
Shopid []interface{} `json:"shopid"`
Shopinfo string `json:"shopinfo"`
Poiweight []interface{} `json:"poiweight"`
Distance string `json:"distance"`
Photos []interface{} `json:"photos"`
} }
func (a *API) GetCoordinateFromAddressByPageAll(address string, cityCode int) (getCoordinateFromAddressByPageAllResult *GetCoordinateFromAddressByPageAllResult, err error) { func (a *API) GetCoordinateFromAddressByPageAll(address string, cityCode int) (getCoordinateFromAddressByPageAllResult *GetCoordinateFromAddressByPageAllResult, err error) {
getCoordinateFromAddressByPageAllResult = &GetCoordinateFromAddressByPageAllResult{}
result, err := a.AccessStorePage("https://restapi.amap.com/v3/place/text", map[string]interface{}{ result, err := a.AccessStorePage("https://restapi.amap.com/v3/place/text", map[string]interface{}{
"s": "rsv3", "s": "rsv3",
"key": "e07ffdf58c8e8672037bef0d6cae7d4a", "key": "e07ffdf58c8e8672037bef0d6cae7d4a",
@@ -107,7 +93,17 @@ func (a *API) GetCoordinateFromAddressByPageAll(address string, cityCode int) (g
"children": "", "children": "",
}) })
if err == nil { if err == nil {
utils.Map2StructByJson(result["pois"].([]interface{})[0], &getCoordinateFromAddressByPageAllResult, false) if len(result["pois"].([]interface{})) > 0 {
str := result["pois"].([]interface{})[0].(map[string]interface{})["location"].(string)
strs := strings.Split(str, ",")
if len(strs) > 0 {
getCoordinateFromAddressByPageAllResult.Lng = utils.Str2Float64(strs[0])
getCoordinateFromAddressByPageAllResult.Lat = utils.Str2Float64(strs[1])
}
getCoordinateFromAddressByPageAllResult.CityName = result["pois"].([]interface{})[0].(map[string]interface{})["cityname"].(string)
getCoordinateFromAddressByPageAllResult.AdName = result["pois"].([]interface{})[0].(map[string]interface{})["adname"].(string)
}
} }
return getCoordinateFromAddressByPageAllResult, err return getCoordinateFromAddressByPageAllResult, err
} }