SignalK / signalk-derived-data

Generates deltas for values derived from signalk values
Apache License 2.0
18 stars 31 forks source link

TypeError: invalid lat ‘NaN’ #84

Closed sergei closed 7 months ago

sergei commented 3 years ago

Getting this error if GPS is not available. Although it's not fatal the message pollutes the /var/log/syslog so it would be nice not to have it

TypeError: invalid lat ‘NaN’
at new LatLonSpherical (/home/pi/.signalk/node_modules/@panaaj/sk-geodesy/latlon-spherical.js:50:31)
at calculator (/home/pi/.signalk/node_modules/signalk-derived-data/calcs/courseData.js:23:11)
sergei commented 3 years ago

I presume this piece of code is supposed to take care of it:

      let pos = vesselPosition
        ? new LatLon(vesselPosition.latitude, vesselPosition.longitude)
        : null

But was is happening the vesselPosition is not undefined or null, but rather the following object:

{
  "longitude": null,
  "latitude": null
}

I guess the statement above can be replaced with:

      let pos = vesselPosition.latitude && vesselPosition.longitude
        ? new LatLon(vesselPosition.latitude, vesselPosition.longitude)
        : null

but that would be rather swiping the dirt under the rug. I guess the question for SignalK maintainers is if position should be allowed to have lat and lon set to NaN

sbender9 commented 3 years ago

I don't think it's defined in the spec which is right. So that code should handle either.

But it should be

vesselPossition && vesselPosition.latitude && vesselPosition.longitude

sergei commented 3 years ago

Thanks, I'll do the PR then.