Skip to content

Commit b951133

Browse files
EllaLiu5meowmeow66
andauthored
fix CityLevelDistrict triggers mismatched city&province (#198)
Co-authored-by: ell <[email protected]>
1 parent 887721c commit b951133

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/main/java/org/bitlap/geocoding/core/impl/RegionInterpreterVisitor.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,19 @@ open class RegionInterpreterVisitor (
384384
}
385385
}
386386

387-
private fun updateCityAndProvince(distinct: RegionEntity?) {
388-
if (distinct == null) return
387+
private fun updateCityAndProvince(district: RegionEntity?) {
388+
if (district == null) return
389389
if (!curDivision.hasCity()) {
390-
curDivision.city = persister.getRegion(distinct.parentId)?.also { city ->
391-
if (!curDivision.hasProvince()) {
392-
curDivision.province = persister.getRegion(city.parentId)
393-
}
390+
// CityLevelDistrict类型的parent是省级因此直接赋值city
391+
if (district.type == CityLevelDistrict) {
392+
curDivision.city = district
393+
} else {
394+
curDivision.city = persister.getRegion(district.parentId)
394395
}
395396
}
397+
if (!curDivision.hasProvince() && curDivision.hasCity()) {
398+
curDivision.province = persister.getRegion(curDivision.city!!.parentId)
399+
}
396400
}
397401

398402
/**

src/test/java/org/bitlap/geocoding/TestNormalizing.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,22 @@ class TestNormalizing {
516516
"绿地城润园"
517517
)
518518
)
519+
// fix CityLevelDistrict 识别错误
520+
assertEquals(
521+
Geocoding.normalizing("陈场镇绿地城润园"),
522+
Address(
523+
420000000000, "湖北省",
524+
429004000000, "仙桃市",
525+
429004000000, "仙桃市",
526+
429004114000, "陈场镇",
527+
429004114000, "陈场镇",
528+
null, null,
529+
null,
530+
null,
531+
null,
532+
"绿地城润园"
533+
)
534+
)
519535
}
520536

521537

0 commit comments

Comments
 (0)