Skip to content

Commit cbd6511

Browse files
committed
Update.
1 parent a4c6dea commit cbd6511

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

iputil/geo/hybrid_reader.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,6 @@ func mergeCityWithPriority(primary City, supplements ...City) City {
9191
if out.District == "" && c.District != "" {
9292
out.District = c.District
9393
}
94-
if out.Latitude == 0 && c.Latitude != 0 {
95-
out.Latitude = c.Latitude
96-
}
97-
if out.Longitude == 0 && c.Longitude != 0 {
98-
out.Longitude = c.Longitude
99-
}
10094
if out.Timezone == "" && c.Timezone != "" {
10195
out.Timezone = c.Timezone
10296
}
@@ -215,6 +209,10 @@ func (h *HybridReader) City(ip net.IP) (City, error) {
215209
primaryISO = strings.ToUpper(c.ISO)
216210
}
217211
}
212+
var maxmindCity City
213+
if h.maxmind != nil {
214+
maxmindCity, _ = h.maxmind.City(ip)
215+
}
218216
var main City
219217
var supplements []City
220218
if primaryISO == "CN" {
@@ -239,15 +237,18 @@ func (h *HybridReader) City(ip net.IP) (City, error) {
239237
}
240238
// Optionally use MaxMind as the last resort for missing fields if ISO matches
241239
if h.maxmind != nil && h.isoMatches(h.maxmind, ip, primaryISO) {
242-
if c, err := h.maxmind.City(ip); err == nil {
243-
supplements = append(supplements, c)
244-
}
240+
supplements = append(supplements, maxmindCity)
241+
}
242+
merged := mergeCityWithPriority(main, supplements...)
243+
if h.maxmind != nil {
244+
merged.Latitude = maxmindCity.Latitude
245+
merged.Longitude = maxmindCity.Longitude
245246
}
246-
return mergeCityWithPriority(main, supplements...), nil
247+
return merged, nil
247248
}
248249
// Non-CN: MaxMind primary; then geocn -> czdbV4 -> czdbV6 -> qqwry (ISO guard)
249250
if h.maxmind != nil {
250-
main, _ = h.maxmind.City(ip)
251+
main = maxmindCity
251252
}
252253
if h.geocn != nil && h.isoMatches(h.geocn, ip, primaryISO) {
253254
if c, err := h.geocn.City(ip); err == nil {
@@ -269,7 +270,12 @@ func (h *HybridReader) City(ip net.IP) (City, error) {
269270
supplements = append(supplements, c)
270271
}
271272
}
272-
return mergeCityWithPriority(main, supplements...), nil
273+
merged := mergeCityWithPriority(main, supplements...)
274+
if h.maxmind != nil {
275+
merged.Latitude = maxmindCity.Latitude
276+
merged.Longitude = maxmindCity.Longitude
277+
}
278+
return merged, nil
273279
}
274280

275281
// ASN returns merged ASN information from all sources

0 commit comments

Comments
 (0)