- GetCoordinateDistrictCode
This commit is contained in:
@@ -145,3 +145,18 @@ func (a *API) CoordinateConvert(lng, lat float64, coordsys string) (retLng, retL
|
||||
}
|
||||
return lng, lat, err
|
||||
}
|
||||
|
||||
func (a *API) GetCoordinateDistrictCode(lng, lat float64) (districtCode int) {
|
||||
params := map[string]interface{}{
|
||||
"location": fmt.Sprintf("%.6f,%.6f", lng, lat),
|
||||
}
|
||||
result, err := a.AccessAPI("geocode/regeo", params)
|
||||
// baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
|
||||
if err == nil {
|
||||
addressComponent := result["regeocode"].(map[string]interface{})["addressComponent"].(map[string]interface{})
|
||||
if strAdcode, ok := addressComponent["adcode"].(string); ok {
|
||||
districtCode = int(utils.Str2Int64WithDefault(strAdcode, 0))
|
||||
}
|
||||
}
|
||||
return districtCode
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user