diff --git a/platformapi/autonavi/autonavi_page.go b/platformapi/autonavi/autonavi_page.go index fe3cd112..acbc52ab 100644 --- a/platformapi/autonavi/autonavi_page.go +++ b/platformapi/autonavi/autonavi_page.go @@ -100,8 +100,21 @@ func (a *API) GetCoordinateFromAddressByPageAll(address string, cityCode int) (g 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) + for _, v := range result["pois"].([]interface{}) { + if getCoordinateFromAddressByPageAllResult.CityName == "" { + if str, ok := v.(map[string]interface{})["cityname"].(string); ok { + getCoordinateFromAddressByPageAllResult.CityName = str + } + } + if getCoordinateFromAddressByPageAllResult.AdName == "" { + if str, ok := v.(map[string]interface{})["adname"].(string); ok { + getCoordinateFromAddressByPageAllResult.AdName = str + } + } + if getCoordinateFromAddressByPageAllResult.CityName != "" && getCoordinateFromAddressByPageAllResult.AdName != "" { + break + } + } } }