Refactor GeoIP data handling to ensure consistent coordinate propagation
- Updated the logic in the geo enrichment process to fill in geographic coordinates even when they are 0.0, enhancing map visualization. - Modified the GeoIP lookup function to always return latitude and longitude, improving the accuracy of location data for the UI. - Improved comments for clarity regarding the importance of geographic data in the mapping context.
This commit is contained in:
@@ -28,7 +28,9 @@ func EnrichUniqueIPsGeo(rows []UniqueIPsRow, g *geoip.Service) {
|
||||
s := res.CityName
|
||||
rows[i].IPs[j].CityName = &s
|
||||
}
|
||||
if res.Latitude != 0 || res.Longitude != 0 {
|
||||
// Заполняем координаты если GeoIP нашёл геоданные (страна/город),
|
||||
// даже если координаты оказались 0.0 (иначе карта может быть пустой).
|
||||
if res.CountryCode != "" || res.CountryName != "" || res.CityName != "" {
|
||||
lat := res.Latitude
|
||||
lon := res.Longitude
|
||||
rows[i].IPs[j].Latitude = &lat
|
||||
|
||||
@@ -101,13 +101,11 @@ func (s *Service) Lookup(ipStr string) (Result, bool) {
|
||||
if rec.City.Names != nil {
|
||||
out.CityName = rec.City.Names["en"]
|
||||
}
|
||||
// Coordinates are used by the UI map.
|
||||
// Note: MaxMind might still return 0/0 for unknown locations.
|
||||
if rec.Location.Latitude != 0 || rec.Location.Longitude != 0 {
|
||||
out.Latitude = rec.Location.Latitude
|
||||
out.Longitude = rec.Location.Longitude
|
||||
ok = true
|
||||
}
|
||||
// Для карты важны координаты. Даже если MaxMind вернул (0,0),
|
||||
// лучше прокидывать их дальше, чем скрывать все точки.
|
||||
out.Latitude = rec.Location.Latitude
|
||||
out.Longitude = rec.Location.Longitude
|
||||
|
||||
if out.CountryCode != "" || out.CountryName != "" || out.CityName != "" {
|
||||
ok = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user