Skip to content

Commit dab9c4e

Browse files
committed
fix(tar1090): fix when aircraft geolocation fails
1 parent f430204 commit dab9c4e

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

annotator_tar1090.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -182,23 +182,17 @@ func (a Tar1090Annotator) Annotate(m APMessage) (APMessage, error) {
182182
}
183183

184184
aircraft := geodist.Coord{Lat: aircraftInfo.Latitude, Lon: aircraftInfo.Longitude}
185+
var mi,km float64
185186
if aircraft.Lat == 0.0 && aircraft.Lon == 0.0 {
186-
// Make the origin the aircraft so distance is zero, which is more
187-
// helpful than if the origin was Null Island.
188-
origin = aircraft
189-
}
190-
mi, km, err := geodist.VincentyDistance(origin, aircraft)
191-
if err != nil {
192-
return m, fmt.Errorf("error calculating distance: %s", err)
193-
}
194-
195-
var navmodes string
196-
for i, mode := range aircraftInfo.NavModes {
197-
if i != 0 {
198-
navmodes = mode + ","
187+
// 0 distance but 0,0 geolocation should indicate geolocation failed.
188+
mi, km = 0,0
189+
} else {
190+
mi, km, err = geodist.VincentyDistance(origin, aircraft)
191+
if err != nil {
192+
return m, fmt.Errorf("error calculating distance: %s", err)
199193
}
200-
navmodes = navmodes + mode
201194
}
195+
202196
c := TAR1090Calculated{
203197
AircraftGeolocation: fmt.Sprintf("%f,%f", aircraftInfo.Latitude, aircraftInfo.Longitude),
204198
AircraftGeolocationLatitude: aircraft.Lat,

0 commit comments

Comments
 (0)