- up
This commit is contained in:
@@ -177,6 +177,27 @@ func (a *API) CoordinateConvert(lng, lat float64, coordsys string) (retLng, retL
|
||||
return lng, lat, err
|
||||
}
|
||||
|
||||
func (a *API) GetCoordinateFromAddress(address string, cityInfo string) (lng, lat float64, districtCode int) {
|
||||
params := map[string]interface{}{
|
||||
"address": address,
|
||||
}
|
||||
if cityInfo != "" {
|
||||
params["city"] = cityInfo
|
||||
}
|
||||
|
||||
result, err := a.AccessAPI("geocode/geo", params)
|
||||
if err == nil {
|
||||
if geocodes, ok := result["geocodes"].([]interface{}); ok && len(geocodes) > 0 {
|
||||
geocode := geocodes[0].(map[string]interface{})
|
||||
locationList := strings.Split(utils.Interface2String(geocode["location"]), ",")
|
||||
if len(locationList) > 1 {
|
||||
return utils.Str2Float64WithDefault(locationList[0], 0), utils.Str2Float64WithDefault(locationList[1], 0), int(utils.Str2Int64(utils.Interface2String(geocode["adcode"])))
|
||||
}
|
||||
}
|
||||
}
|
||||
return lng, lat, 0
|
||||
}
|
||||
|
||||
// 这里的District指的是实际的District,有些市是没有区的,比如东莞,这种情况下返回的区码是一个假的区域,即市的编码加上9000000
|
||||
func (a *API) GetCoordinateDistrictCode(lng, lat float64) (districtCode int) {
|
||||
result, err := a.GetCoordinateAreaInfo(lng, lat)
|
||||
|
||||
@@ -83,3 +83,8 @@ func TestGetDistricts(t *testing.T) {
|
||||
}
|
||||
t.Log(utils.Format4Output(districtList, false))
|
||||
}
|
||||
|
||||
func TestGetCoordinateFromAddress(t *testing.T) {
|
||||
lng, lat, districtCode := autonaviAPI.GetCoordinateFromAddress("天府广场", "成都市")
|
||||
t.Logf("lng:%f, lat:%f, districtCode:%d", lng, lat, districtCode)
|
||||
}
|
||||
|
||||
@@ -266,7 +266,7 @@ type PageShopInfo struct {
|
||||
CanRefund int `json:"can_refund"`
|
||||
Category string `json:"category"`
|
||||
CityID string `json:"city_id"`
|
||||
CurrentBusinessTime string `json:"current_business_time"`
|
||||
CurrentBusinessTime interface{} `json:"current_business_time"` // 无值时为空字符串,有值时为对象:{"end":"20:45","start":"08:05"}
|
||||
DeliveryInfo []interface{} `json:"delivery_info"`
|
||||
DeliveryMode struct {
|
||||
Tag []interface{} `json:"tag"`
|
||||
@@ -300,7 +300,7 @@ type PageShopInfo struct {
|
||||
Qualification string `json:"qualification"`
|
||||
RecentOrderNum int `json:"recent_order_num"`
|
||||
ShopID string `json:"shop_id"`
|
||||
ShopScore int `json:"shop_score"`
|
||||
ShopScore float64 `json:"shop_score"`
|
||||
ShopSourceFrom int `json:"shop_source_from"`
|
||||
SkuCount int `json:"sku_count"`
|
||||
TakeoutCost int `json:"takeout_cost"`
|
||||
|
||||
@@ -181,7 +181,7 @@ func (a *API) AccessStorePage(fullURL string, formData map[string]interface{}) (
|
||||
retVal = jsonResult1
|
||||
code := jsonResult1["code"].(string)
|
||||
if code == ResponseCodeSuccess {
|
||||
retVal = jsonResult1["result"].(map[string]interface{})
|
||||
retVal, _ = jsonResult1["result"].(map[string]interface{})
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
}
|
||||
newErr := utils.NewErrorCode(jsonResult1["msg"].(string), code)
|
||||
|
||||
@@ -255,6 +255,10 @@ func Float64TwoInt64(data float64) int64 {
|
||||
return int64(math.Round(data))
|
||||
}
|
||||
|
||||
func Float64ToStr(data float64) string {
|
||||
return fmt.Sprint(data)
|
||||
}
|
||||
|
||||
// timestamp is in second
|
||||
func Timestamp2Str(timestamp int64) string {
|
||||
return Time2Str(Timestamp2Time(timestamp))
|
||||
|
||||
Reference in New Issue
Block a user