- refactor GetDistrictLevel

This commit is contained in:
gazebo
2018-12-06 11:27:31 +08:00
parent 13caad7953
commit 8cf6d7eb51

View File

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