From 4d08df34f0a4c08483d381af62036ddbe37ba2dc Mon Sep 17 00:00:00 2001 From: suyl <770236076@qq.com> Date: Tue, 11 May 2021 16:13:37 +0800 Subject: [PATCH] aa --- platformapi/autonavi/autonavi_page.go | 36 ++++++++++++--------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/platformapi/autonavi/autonavi_page.go b/platformapi/autonavi/autonavi_page.go index ef0f92e6..fe3cd112 100644 --- a/platformapi/autonavi/autonavi_page.go +++ b/platformapi/autonavi/autonavi_page.go @@ -69,28 +69,14 @@ func (a *API) GetCoordinateFromAddressByPage(address string, cityCode int) (lng, } type GetCoordinateFromAddressByPageAllResult struct { - ID string `json:"id"` - Parent []interface{} `json:"parent"` - Childtype []interface{} `json:"childtype"` - Name string `json:"name"` - 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"` + Lng float64 `json:"lng"` + Lat float64 `json:"lat"` + AdName string `json:"adName"` + CityName string `json:"cityName"` } 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{}{ "s": "rsv3", "key": "e07ffdf58c8e8672037bef0d6cae7d4a", @@ -107,7 +93,17 @@ func (a *API) GetCoordinateFromAddressByPageAll(address string, cityCode int) (g "children": "", }) 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 }