- refactor GetDistrictLevel
This commit is contained in:
@@ -69,6 +69,16 @@ const (
|
|||||||
DistrictLevelStreet = 4
|
DistrictLevelStreet = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
levelStr2IntMap = map[string]int{
|
||||||
|
"country": DistrictLevelCountry,
|
||||||
|
"province": DistrictLevelProvince,
|
||||||
|
"city": DistrictLevelCity,
|
||||||
|
"district": DistrictLevelDistrict,
|
||||||
|
"street": DistrictLevelStreet,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
type District struct {
|
type District struct {
|
||||||
Adcode string `json:"adcode"` // 国家行政编码
|
Adcode string `json:"adcode"` // 国家行政编码
|
||||||
Lng float64 `json:"lng"`
|
Lng float64 `json:"lng"`
|
||||||
@@ -233,17 +243,5 @@ func (a *API) getDistrictsFromInterface(districts interface{}) (districtList []*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetDistrictLevel(levelName string) (level int) {
|
func GetDistrictLevel(levelName string) (level int) {
|
||||||
switch levelName {
|
return levelStr2IntMap[levelName]
|
||||||
case "country":
|
|
||||||
level = 0
|
|
||||||
case "province":
|
|
||||||
level = 1
|
|
||||||
case "city":
|
|
||||||
level = 2
|
|
||||||
case "district":
|
|
||||||
level = 3
|
|
||||||
case "street":
|
|
||||||
level = 4
|
|
||||||
}
|
|
||||||
return level
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user