@@ -1,385 +1,385 @@
package autonavi
package autonavi
//
import (
//import (
"bytes"
// "bytes "
"crypto/md5 "
// "crypto/md5 "
"fmt "
// "fmt "
"git.rosy.net.cn/baseapi/platformapi "
// "git.rosy.net.cn/baseapi/platformapi "
"git.rosy.net.cn/baseapi/utils "
// "git.rosy.net.cn/baseapi/utils "
"net/http "
// "net/http "
"sort "
// "sort "
"strings "
// )
)
//
// const (
const (
// signKey = "sig"
signKey = "sig"
// prodURL = "https://restapi.amap.com"
prodURL = "https://restapi.amap.com"
// prodURLv3 = "/v3"
prodURLv3 = "/v3"
// prodURLFullv3 = prodURL + prodURLv3
prodURLFullv3 = prodURL + prodURLv3
//
// batchAPIStr = "batch"
batchAPIStr = "batch"
// )
)
//
// const (
const (
// StatusCodeFailed = "0"
StatusCodeFailed = "0"
// StatusCodeSuccess = "1"
StatusCodeSuccess = "1"
// )
)
//
// const (
const (
// InfoCode_OK = "10000"
InfoCode_OK = "10000"
// InfoCode_ACCESS_TOO_FREQUENT = "10004"
InfoCode_ACCESS_TOO_FREQUENT = "10004"
// InfoCode_QPS_HAS_EXCEEDED_THE_LIMIT = "10014"
InfoCode_QPS_HAS_EXCEEDED_THE_LIMIT = "10014"
// InfoCode_SERVER_IS_BUSY = "10016"
InfoCode_SERVER_IS_BUSY = "10016"
// InfoCode_RESOURCE_UNAVAILABLE = "10017"
InfoCode_RESOURCE_UNAVAILABLE = "10017"
// InfoCode_CQPS_HAS_EXCEEDED_THE_LIMIT = "10019"
InfoCode_CQPS_HAS_EXCEEDED_THE_LIMIT = "10019"
// InfoCode_CKQPS_HAS_EXCEEDED_THE_LIMIT = "10020"
InfoCode_CKQPS_HAS_EXCEEDED_THE_LIMIT = "10020"
// InfoCode_CIQPS_HAS_EXCEEDED_THE_LIMIT = "10021"
InfoCode_CIQPS_HAS_EXCEEDED_THE_LIMIT = "10021"
// InfoCode_CIKQPS_HAS_EXCEEDED_THE_LIMIT = "10022"
InfoCode_CIKQPS_HAS_EXCEEDED_THE_LIMIT = "10022"
// InfoCode_KQPS_HAS_EXCEEDED_THE_LIMIT = "10023"
InfoCode_KQPS_HAS_EXCEEDED_THE_LIMIT = "10023"
// )
)
//
// const (
const (
// CoordSysAutonavi = "autonavi"
CoordSysAutonavi = "autonavi"
// CoordSysGPS = "gps"
CoordSysGPS = "gps"
// CoordSysMapbar = "mapbar"
CoordSysMapbar = "mapbar"
// CoordSysBaidu = "baidu"
CoordSysBaidu = "baidu"
// )
)
//
// const (
const (
// FakeDistrictPadding = 9000000
FakeDistrictPadding = 9000000
// MaxConvertCount = 40
MaxConvertCount = 40
// )
)
//
//var (
var (
// exceedLimitCodes = map[ string] int{
exceedLimitCodes = map [ string] int {
// InfoCode_ACCESS_TOO_FREQUENT: 1 ,
InfoCode_ACCESS_TOO_FREQUENT: 1 ,
// InfoCode_QPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
InfoCode_QPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
// InfoCode_CQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
InfoCode_CQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
// InfoCode_CKQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
InfoCode_CKQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
// InfoCode_CIQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
InfoCode_CIQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
// InfoCode_CIKQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
InfoCode_CIKQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
// InfoCode_KQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
InfoCode_KQPS_HAS_EXCEEDED_THE_LIMIT: 1 ,
// }
}
//
// canRetryCodes = map[ string] int{
canRetryCodes = map [ string] int {
// InfoCode_SERVER_IS_BUSY: 1 ,
InfoCode_SERVER_IS_BUSY: 1 ,
// }
}
// )
)
//
// const (
const (
// DistrictLevelCountry = 0
DistrictLevelCountry = 0
// DistrictLevelProvince = 1
DistrictLevelProvince = 1
// DistrictLevelCity = 2
DistrictLevelCity = 2
// DistrictLevelDistrict = 3
DistrictLevelDistrict = 3
// DistrictLevelStreet = 4
DistrictLevelStreet = 4
// )
)
//
// const (
const (
// RoadLevelAll = 0 // 显示所有道路
RoadLevelAll = 0 // 显示所有道路
// RoadLevelMain = 1 // 过滤非主干道路,仅输出主干道路数据
RoadLevelMain = 1 // 过滤非主干道路,仅输出主干道路数据
//
// HomeOrCorpDef = 0 // 不对召回的排序策略进行干扰。
HomeOrCorpDef = 0 // 不对召回的排序策略进行干扰。
// HomeOrCorpPreferHome = 1 // 综合大数据分析将居家相关的 POI 内容优先返回,即优化返回结果中 pois 字段的poi顺序。
HomeOrCorpPreferHome = 1 // 综合大数据分析将居家相关的 POI 内容优先返回,即优化返回结果中 pois 字段的poi顺序。
// HomeOrCorpPreferCorp = 2 // 综合大数据分析将公司相关的 POI 内容优先返回,即优化返回结果中 pois 字段的poi顺序。
HomeOrCorpPreferCorp = 2 // 综合大数据分析将公司相关的 POI 内容优先返回,即优化返回结果中 pois 字段的poi顺序。
// )
)
//
//var (
var (
// levelStr2IntMap = map[ string] int{
levelStr2IntMap = map [ string] int {
// "country": DistrictLevelCountry,
"country": DistrictLevelCountry ,
// "province": DistrictLevelProvince,
"province": DistrictLevelProvince ,
// "city": DistrictLevelCity,
"city": DistrictLevelCity ,
// "district": DistrictLevelDistrict,
"district": DistrictLevelDistrict ,
// "street": DistrictLevelStreet,
"street": DistrictLevelStreet ,
// }
}
// )
)
//
// type District struct {
type District struct {
// Adcode string ` json:"adcode"` // 国家行政编码
Adcode string ` json:"adcode"` // 国家行政编码
// Lng float64 ` json:"lng"`
Lng float64 ` json:"lng" `
// Lat float64 ` json:"lat"`
Lat float64 ` json:"lat" `
// CityCode string ` json:"citycode"` // 电话区号
CityCode string ` json:"citycode"` // 电话区号
// Level int ` json:"level"`
Level int ` json:"level" `
// Name string ` json:"name"`
Name string ` json:"name" `
// Districts []*District ` json:"districts"`
Districts [ ] * District ` json:"districts" `
// }
}
//
// type Coordinate struct {
type Coordinate struct {
// Lng float64 ` json:"lng"`
Lng float64 ` json:"lng" `
// Lat float64 ` json:"lat"`
Lat float64 ` json:"lat" `
// }
}
//
// type ResponseResult map[ string] interface{ }
type ResponseResult map [ string] interface{ }
//
// type API struct {
type API struct {
// platformapi. APICookie
platformapi. APICookie
//
// client *http. Client
client * http . Client
// config * platformapi. APIConfig
config * platformapi. APIConfig
// key string
key string
// }
}
//
// func (a *API) SetKey(key string) {
func ( a * API ) SetKey ( key string ) {
// a.key = key
a . key = key
// }
}
//
// type BuildingOrNeighborInfo struct {
type BuildingOrNeighborInfo struct {
// Name string ` json:"name"`
Name string ` json:"name" `
// Type string ` json:"type"`
Type string ` json:"type" `
// }
}
//
// type BusinessAreaInfo struct {
type BusinessAreaInfo struct {
// ID string ` json:"id"`
ID string ` json:"id" `
// Location string ` json:"location"`
Location string ` json:"location" `
// Name string ` json:"name"`
Name string ` json:"name" `
// }
}
//
// type StreetNumberInfo struct {
type StreetNumberInfo struct {
// Direction string ` json:"direction"`
Direction string ` json:"direction" `
// Distance string ` json:"distance"`
Distance string ` json:"distance" `
// Location string ` json:"location"`
Location string ` json:"location" `
// Number string ` json:"number"`
Number string ` json:"number" `
// Street string ` json:"street"`
Street string ` json:"street" `
// }
}
//
// type AoiInfo struct {
type AoiInfo struct {
// Adcode string ` json:"adcode"`
Adcode string ` json:"adcode" `
// Area string ` json:"area"`
Area string ` json:"area" `
// Distance string ` json:"distance"`
Distance string ` json:"distance" `
// ID string ` json:"id"`
ID string ` json:"id" `
// Location string ` json:"location"`
Location string ` json:"location" `
// Name string ` json:"name"`
Name string ` json:"name" `
// Type string ` json:"type"`
Type string ` json:"type" `
// }
}
//
// type PoiInfo struct {
type PoiInfo struct {
// Address string ` json:"address"`
Address string ` json:"address" `
// Businessarea string ` json:"businessarea"`
Businessarea string ` json:"businessarea" `
// Direction string ` json:"direction"`
Direction string ` json:"direction" `
// Distance string ` json:"distance"`
Distance string ` json:"distance" `
// ID string ` json:"id"`
ID string ` json:"id" `
// Location string ` json:"location"`
Location string ` json:"location" `
// Name string ` json:"name"`
Name string ` json:"name" `
// Poiweight string ` json:"poiweight"`
Poiweight string ` json:"poiweight" `
// Tel string ` json:"tel"`
Tel string ` json:"tel" `
// Type string ` json:"type"`
Type string ` json:"type" `
// }
}
//
// type RoadinterInfo struct {
type RoadinterInfo struct {
// Direction string ` json:"direction"`
Direction string ` json:"direction" `
// Distance string ` json:"distance"`
Distance string ` json:"distance" `
// FirstID string ` json:"first_id"`
FirstID string ` json:"first_id" `
// FirstName string ` json:"first_name"`
FirstName string ` json:"first_name" `
// Location string ` json:"location"`
Location string ` json:"location" `
// SecondID string ` json:"second_id"`
SecondID string ` json:"second_id" `
// SecondName string ` json:"second_name"`
SecondName string ` json:"second_name" `
// }
}
//
// type RoadInfo struct {
type RoadInfo struct {
// Direction string ` json:"direction"`
Direction string ` json:"direction" `
// Distance string ` json:"distance"`
Distance string ` json:"distance" `
// ID string ` json:"id"`
ID string ` json:"id" `
// Location string ` json:"location"`
Location string ` json:"location" `
// Name string ` json:"name"`
Name string ` json:"name" `
// }
}
//
// type AddressComponentInfo struct {
type AddressComponentInfo struct {
// Adcode string ` json:"adcode"`
Adcode string ` json:"adcode" `
// Building * BuildingOrNeighborInfo ` json:"building"`
Building * BuildingOrNeighborInfo ` json:"building" `
// // BusinessAreas []*BusinessAreaInfo `json:"businessAreas"`
// BusinessAreas []*BusinessAreaInfo `json:"businessAreas"`
// City string ` json:"city"`
City string ` json:"city" `
// Citycode string ` json:"citycode"`
Citycode string ` json:"citycode" `
// Country string ` json:"country"`
Country string ` json:"country" `
// District string ` json:"district"`
District string ` json:"district" `
// Neighborhood * BuildingOrNeighborInfo ` json:"neighborhood"`
Neighborhood * BuildingOrNeighborInfo ` json:"neighborhood" `
// Province string ` json:"province"`
Province string ` json:"province" `
// StreetNumber * StreetNumberInfo ` json:"streetNumber"`
StreetNumber * StreetNumberInfo ` json:"streetNumber" `
// Towncode string ` json:"towncode"`
Towncode string ` json:"towncode" `
// Township string ` json:"township"`
Township string ` json:"township" `
// }
}
//
// type RegeoCodeInfo struct {
type RegeoCodeInfo struct {
// AddressComponent * AddressComponentInfo ` json:"addressComponent"`
AddressComponent * AddressComponentInfo ` json:"addressComponent" `
// Aois []* AoiInfo ` json:"aois"`
Aois [ ] * AoiInfo ` json:"aois" `
// FormattedAddress string ` json:"formatted_address"`
FormattedAddress string ` json:"formatted_address" `
// Pois []* PoiInfo ` json:"pois"`
Pois [ ] * PoiInfo ` json:"pois" `
// Roadinters []* RoadinterInfo ` json:"roadinters"`
Roadinters [ ] * RoadinterInfo ` json:"roadinters" `
// Roads []* RoadInfo ` json:"roads"`
Roads [ ] * RoadInfo ` json:"roads" `
// }
}
//
// type tBatchAPIParams struct {
type tBatchAPIParams struct {
// APIStr string
APIStr string
// APIParams map[ string] interface{ }
APIParams map [ string] interface{ }
// }
}
//
// type tBatchAPIResponse struct {
type tBatchAPIResponse struct {
// Result ResponseResult
Result ResponseResult
// Err error
Err error
// }
}
//
// func New(key string, config ...* platformapi. APIConfig) *API {
func New ( key string , config ... * platformapi. APIConfig) * API {
// curConfig := platformapi. DefAPIConfig
curConfig := platformapi. DefAPIConfig
// if len(config) > 0 {
if len ( config ) > 0 {
// curConfig = *config[0 ]
curConfig = * config [ 0 ]
// }
}
// return & API{
return & API {
// key: key,
key : key ,
// client: &http. Client{ Timeout: curConfig. ClientTimeout} ,
client: & http . Client{ Timeout: curConfig. ClientTimeout} ,
// config: & curConfig,
config: & curConfig ,
// }
}
// }
}
//
// func (a *API) signParams( mapData map[ string] interface{}) string {
func ( a * API ) signParams( mapData map [ string] interface{ } ) string {
// keys := make([]string, 0 )
keys := make ( [ ] string , 0 )
// for k := range mapData {
for k := range mapData {
// if k != signKey {
if k != signKey {
// keys = append(keys, k )
keys = append ( keys , k )
// }
}
// }
}
// sort. Strings( keys)
sort . Strings( keys )
//
// finalStr := ""
finalStr := ""
// for _, k := range keys {
for _ , k := range keys {
// finalStr += k + "=" + fmt. Sprint( mapData[k] )
finalStr += k + "=" + fmt . Sprint( mapData[ k ] )
// }
}
//
// return fmt.Sprintf("%X", md5.Sum([]byte(finalStr)) )
return fmt . Sprintf ( "%X" , md5 . Sum ( [ ] byte ( finalStr ) ) )
// }
}
//
// func coordinate2String(lng, lat float64) (str string) {
func coordinate2String( lng , lat float64 ) ( str string ) {
// return fmt. Sprintf( "%.6f,%.6f", lng, lat)
return fmt . Sprintf( "%.6f,%.6f", lng , lat )
// }
}
//
// func (a *API) AccessAPI( apiStr string, params map[ string] interface{}) ( retVal ResponseResult, err error) {
func ( a * API ) AccessAPI( apiStr string, params map [ string] interface{ } ) ( retVal ResponseResult, err error ) {
// params2 := utils.MergeMaps(utils.Params2Map("key", a.key, "output", "json"), params)
params2 := utils . MergeMaps ( utils . Params2Map ( "key" , a . key , "output" , "json" ) , params )
// params2[ signKey] = a. signParams( params2)
params2[ signKey] = a . signParams( params2 )
//
// err = platformapi. AccessPlatformAPIWithRetry(a. client,
err = platformapi. AccessPlatformAPIWithRetry( a . client ,
// func() *http. Request {
func ( ) * http . Request {
// request, _ := http.NewRequest(http.MethodGet, utils. GenerateGetURL( prodURLFullv3, apiStr, params2), nil)
request, _ := http . NewRequest ( http . MethodGet , utils . GenerateGetURL( prodURLFullv3, apiStr , params2 ) , nil )
// return request
return request
// } ,
} ,
// a. config,
a . config ,
// func(response *http.Response, bodyStr string, jsonResult1 map[ string] interface{}) ( errLevel string, err error) {
func ( response * http . Response , bodyStr string, jsonResult1 map [ string] interface{ } ) ( errLevel string, err error ) {
// if jsonResult1 == nil {
if jsonResult1 == nil {
// return platformapi. ErrLevelRecoverableErr, fmt. Errorf( "mapData is nil")
return platformapi. ErrLevelRecoverableErr, fmt . Errorf( "mapData is nil" )
// }
}
// status := jsonResult1[ "status"].( string)
status := jsonResult1[ "status"] . ( string )
// if status == StatusCodeSuccess {
if status == StatusCodeSuccess {
// retVal = jsonResult1
retVal = jsonResult1
// return platformapi. ErrLevelSuccess, nil
return platformapi. ErrLevelSuccess, nil
// }
}
// infoCode := jsonResult1[ "infocode"].( string)
infoCode := jsonResult1[ "infocode"] . ( string )
// newErr := utils. NewErrorCode( jsonResult1[ "info"].(string), infoCode)
newErr := utils . NewErrorCode( jsonResult1[ "info"] . ( string ) , infoCode )
// if _, ok := exceedLimitCodes[ infoCode]; ok {
if _ , ok := exceedLimitCodes[ infoCode] ; ok {
// return platformapi. ErrLevelExceedLimit, newErr
return platformapi. ErrLevelExceedLimit, newErr
// } else if _, ok := canRetryCodes[ infoCode]; ok {
} else if _ , ok := canRetryCodes[ infoCode] ; ok {
// return platformapi. ErrLevelRecoverableErr, newErr
return platformapi. ErrLevelRecoverableErr, newErr
// } else {
} else {
// return platformapi. ErrLevelCodeIsNotOK, newErr
return platformapi. ErrLevelCodeIsNotOK, newErr
// }
}
// } )
} )
// return retVal, err
return retVal, err
// }
}
//
// func (a *API) AccessAPI3( apiStr string, params map[ string] interface{}) ( retVal ResponseResult, err error) {
func ( a * API ) AccessAPI3( apiStr string, params map [ string] interface{ } ) ( retVal ResponseResult, err error ) {
// err = platformapi. AccessPlatformAPIWithRetry(a. client,
err = platformapi. AccessPlatformAPIWithRetry( a . client ,
// func() *http. Request {
func ( ) * http . Request {
// request, _ := http.NewRequest(http.MethodGet, utils. GenerateGetURL( BaseUrl, apiStr, params), nil)
request, _ := http . NewRequest ( http . MethodGet , utils . GenerateGetURL( BaseUrl, apiStr , params ) , nil )
// return request
return request
// } ,
} ,
// a. config,
a . config ,
// func(response *http.Response, bodyStr string, jsonResult1 map[ string] interface{}) ( errLevel string, err error) {
func ( response * http . Response , bodyStr string, jsonResult1 map [ string] interface{ } ) ( errLevel string, err error ) {
// if jsonResult1 == nil {
if jsonResult1 == nil {
// return platformapi. ErrLevelRecoverableErr, fmt. Errorf( "mapData is nil")
return platformapi. ErrLevelRecoverableErr, fmt . Errorf( "mapData is nil" )
// }
}
// status := jsonResult1[ "status"].( string)
status := jsonResult1[ "status"] . ( string )
// if status == StatusCodeSuccess {
if status == StatusCodeSuccess {
// retVal = jsonResult1
retVal = jsonResult1
// return platformapi. ErrLevelSuccess, nil
return platformapi. ErrLevelSuccess, nil
// }
}
// infoCode := jsonResult1[ "infocode"].( string)
infoCode := jsonResult1[ "infocode"] . ( string )
// newErr := utils. NewErrorCode( jsonResult1[ "info"].(string), infoCode)
newErr := utils . NewErrorCode( jsonResult1[ "info"] . ( string ) , infoCode )
// if _, ok := exceedLimitCodes[ infoCode]; ok {
if _ , ok := exceedLimitCodes[ infoCode] ; ok {
// return platformapi. ErrLevelExceedLimit, newErr
return platformapi. ErrLevelExceedLimit, newErr
// } else if _, ok := canRetryCodes[ infoCode]; ok {
} else if _ , ok := canRetryCodes[ infoCode] ; ok {
// return platformapi. ErrLevelRecoverableErr, newErr
return platformapi. ErrLevelRecoverableErr, newErr
// } else {
} else {
// return platformapi. ErrLevelCodeIsNotOK, newErr
return platformapi. ErrLevelCodeIsNotOK, newErr
// }
}
// } )
} )
// return retVal, err
return retVal, err
// }
}
//
// func (a *API) BatchAccessAPI( apiList []* tBatchAPIParams) (retVal []*tBatchAPIResponse, err error) {
func ( a * API ) BatchAccessAPI( apiList [ ] * tBatchAPIParams) ( retVal [ ] * tBatchAPIResponse , err error ) {
// if len(apiList) == 0 {
if len ( apiList ) == 0 {
// return nil, nil
return nil , nil
// }
}
//
// var ops []map[ string] interface{ }
var ops [ ] map [ string] interface{ }
// for _, v := range apiList {
for _ , v := range apiList {
// params2 := utils.MergeMaps(utils.Params2Map("key", a.key, "output", "json"), v. APIParams)
params2 := utils . MergeMaps ( utils . Params2Map ( "key" , a . key , "output" , "json" ) , v . APIParams )
// params2[ signKey] = a. signParams( params2)
params2[ signKey] = a . signParams( params2 )
// op := make(map[ string] interface{} )
op := make ( map [ string] interface{ } )
// op["url"] = utils. GenerateGetURL( prodURLv3, v.APIStr, params2)
op [ "url" ] = utils . GenerateGetURL( prodURLv3, v . APIStr , params2 )
// ops = append(ops, op )
ops = append ( ops , op )
// }
}
// params2 := map[ string] interface{} {
params2 := map [ string] interface{ } {
// "ops": ops,
"ops" : ops ,
// }
}
//
// err = platformapi. AccessPlatformAPIWithRetry(a. client,
err = platformapi. AccessPlatformAPIWithRetry( a . client ,
// func() *http. Request {
func ( ) * http . Request {
// request, _ := http.NewRequest(http.MethodGet, utils. GenerateGetURL( prodURLFullv3, batchAPIStr, utils.Params2Map("key", a.key)) ,
request, _ := http . NewRequest ( http . MethodGet , utils . GenerateGetURL( prodURLFullv3, batchAPIStr, utils . Params2Map ( "key" , a . key ) ) ,
// bytes. NewReader(utils. MustMarshal( params2)) )
bytes. NewReader( utils . MustMarshal( params2) ) )
// request. Header.Set( "charset", "UTF-8")
request. Header. Set ( "charset", "UTF-8" )
// request. Header.Set( "Content-Type", "application/json")
request. Header. Set ( "Content-Type", "application/json" )
// return request
return request
// } ,
} ,
// a. config,
a . config ,
// func(response *http.Response, bodyStr string, jsonResult1 map[ string] interface{}) ( errLevel string, err error) {
func ( response * http . Response , bodyStr string, jsonResult1 map [ string] interface{ } ) ( errLevel string, err error ) {
// if jsonResult1 == nil {
if jsonResult1 == nil {
// return platformapi. ErrLevelRecoverableErr, fmt. Errorf( "mapData is nil")
return platformapi. ErrLevelRecoverableErr, fmt . Errorf( "mapData is nil" )
// }
}
// if resultList, ok := jsonResult1[ platformapi. KeyData].([]interface{}); ok {
if resultList , ok := jsonResult1[ platformapi. KeyData] . ( [ ] interface { } ) ; ok {
// for _, v := range resultList {
for _ , v := range resultList {
// jsonResult1 := v.(map[ string] interface{} )
jsonResult1 := v . ( map [ string] interface{ } )
// status := int(utils. ForceInterface2Int64( jsonResult1[ "status"]) )
status := int ( utils . ForceInterface2Int64( jsonResult1[ "status"] ) )
// if status == http. StatusOK {
if status == http . StatusOK {
// jsonResult1 := v.(map[ string] interface{})["body"].(map[ string] interface{} )
jsonResult1 := v . ( map [ string] interface{ } ) [ "body" ] . ( map [ string] interface{ } )
// var retVal2 map[ string] interface{ }
var retVal2 map [ string] interface{ }
// var err2 error
var err2 error
// status := jsonResult1[ "status"].( string)
status := jsonResult1[ "status"] . ( string )
// if status == StatusCodeSuccess {
if status == StatusCodeSuccess {
// retVal2 = jsonResult1
retVal2 = jsonResult1
// } else {
} else {
// infoCode := jsonResult1[ "infocode"].( string)
infoCode := jsonResult1[ "infocode"] . ( string )
// err2 = utils. NewErrorCode( jsonResult1[ "info"].(string), infoCode)
err2 = utils . NewErrorCode( jsonResult1[ "info"] . ( string ) , infoCode )
// }
}
// retVal = append( retVal, & tBatchAPIResponse{
retVal = append( retVal, & tBatchAPIResponse {
// Result: retVal2,
Result: retVal2 ,
// Err: err2,
Err: err2 ,
// } )
} )
// }
}
// }
}
// errLevel = platformapi. ErrLevelSuccess
errLevel = platformapi. ErrLevelSuccess
// } else {
} else {
// infoCode := jsonResult1[ "infocode"].( string)
infoCode := jsonResult1[ "infocode"] . ( string )
// err = utils. NewErrorCode( jsonResult1[ "info"].(string), infoCode)
err = utils . NewErrorCode( jsonResult1[ "info"] . ( string ) , infoCode )
// if _, ok := exceedLimitCodes[ infoCode]; ok {
if _ , ok := exceedLimitCodes[ infoCode] ; ok {
// errLevel = platformapi. ErrLevelExceedLimit
errLevel = platformapi. ErrLevelExceedLimit
// } else if _, ok := canRetryCodes[ infoCode]; ok {
} else if _ , ok := canRetryCodes[ infoCode] ; ok {
// errLevel = platformapi. ErrLevelRecoverableErr
errLevel = platformapi. ErrLevelRecoverableErr
// } else {
} else {
// errLevel = platformapi. ErrLevelCodeIsNotOK
errLevel = platformapi. ErrLevelCodeIsNotOK
// }
}
// }
}
// return errLevel, err
return errLevel, err
// } )
} )
// return retVal, err
return retVal, err
// }
}
// 为了方便调用者编码,如果失败,也会返回未转换的原始值
// 为了方便调用者编码,如果失败,也会返回未转换的原始值
/* func (a *API) CoordinateConvert(lng, lat float64, coordsys string) (retLng, retLat float64, err error) {
func ( a * API ) CoordinateConvert ( lng , lat float64 , coordsys string) ( retLng , retLat float64, err error ) {
// outCoords, err := a.BatchCoordinateConvert([]*Coordinate{
// outCoords, err := a.BatchCoordinateConvert([]*Coordinate{
// &Coordinate{
// &Coordinate{
// Lng: lng,
// Lng: lng,
@@ -552,9 +552,9 @@ func (a *API) getDistrictsFromInterface(districts interface{}) (districtList []*
func GetDistrictLevel ( levelName string ) ( level int ) {
func GetDistrictLevel ( levelName string ) ( level int ) {
return levelStr2IntMap [ levelName ]
return levelStr2IntMap [ levelName ]
}
}
*/
// 两点之间的步行距离,单位为米
// 两点之间的步行距离,单位为米
/* func (a *API) WalkingDistance(lng1, lat1, lng2, lat2 float64) ( distance float64) {
func ( a * API ) WalkingDistance ( lng1 , lat1 , lng2 , lat2 float64 ) ( distance float64) {
params := map [ string ] interface { } {
params := map [ string ] interface { } {
"origin" : coordinate2String ( lng1 , lat1 ) ,
"origin" : coordinate2String ( lng1 , lat1 ) ,
"destination" : coordinate2String ( lng2 , lat2 ) ,
"destination" : coordinate2String ( lng2 , lat2 ) ,
@@ -593,11 +593,9 @@ func (a *API) BatchWalkingDistance(srcLng, srcLat float64, destCoords []*Coordin
}
}
return distanceList , err
return distanceList , err
}
}
*/
/*-----------------------------------------------------*/
// 这里的District指的是实际的District, 有些市是没有区的, 比如东莞, 这种情况下返回的区码是一个假的区域, 即市的编码加上9000000
// 这里的District指的是实际的District, 有些市是没有区的, 比如东莞, 这种情况下返回的区码是一个假的区域, 即市的编码加上9000000
/* func (a *API) GetCoordinateDistrictCode(lng, lat float64) (districtCode int) {
func ( a * API ) GetCoordinateDistrictCode ( lng , lat float64 ) ( districtCode int ) {
result , err := a . GetCoordinateAreaInfo ( lng , lat )
result , err := a . GetCoordinateAreaInfo ( lng , lat )
if err == nil {
if err == nil {
addressComponent := result [ "regeocode" ] . ( map [ string ] interface { } ) [ "addressComponent" ] . ( map [ string ] interface { } )
addressComponent := result [ "regeocode" ] . ( map [ string ] interface { } ) [ "addressComponent" ] . ( map [ string ] interface { } )
@@ -651,4 +649,3 @@ func (a *API) GetCoordinateCityInfo(lng, lat float64) (cityName, cityCode string
}
}
return cityName , cityCode
return cityName , cityCode
}
}
*/