3 #=======================================================================
7 # ©opyleft 2002– Øyvind A. Holm <sunny@sunbase.org>
8 # License: GNU General Public License, see end of file for legal stuff.
9 #=======================================================================
18 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
21 push(@main::version_array
, $rcs_id);
22 $VERSION = ($rcs_id =~ / (\d+) /, $1);
25 @EXPORT = qw(&list_nearest_waypoints &ddd_to_dms ¤t_pos ¤t_pos);
30 sub list_nearest_waypoints
{
32 my ($Lat, $Lon, $Count) = @_;
35 my $waypoint_file = "/home/sunny/gps/waypoints.gpx";
37 # FIXME: Incredible unfinished and kludgy.
38 if (open(WaypFP
, "$main::Cmd{'gpsbabel'} -i gpx -f $waypoint_file " .
39 "-x radius,lat=$Lat,lon=$Lon,distance=1000 " .
42 my $Str = join("", <WaypFP
>);
44 ^.*?
<wpt\s
.*?
>.*?
<name
>(.+?
)</name>.*?</wpt
>.*?
45 .*?
<wpt\s
.*?
>.*?
<name
>(.+?
)</name>.*?</wpt
>.*?
46 .*?
<wpt\s
.*?
>.*?
<name
>(.+?
)</name>.*?</wpt
>.*$
52 die("$main::progname: Cannot open $main::Cmd{'gpsbabel'} pipe: $!\n");
58 # Convert floating-point degrees into D°M'S.S" (ISO-8859-1).
59 # Necessary for import into GPSman. Based on toDMS() from
60 # gpstrans-0.39 to ensure compatibility.
64 my ($Hour, $Min, $Sec) =
68 ($ddd =~ /^\-?(\d*)(\.\d+)?$/) || return(undef);
69 length($ddd) || ($ddd = 0);
76 $ddd = ($ddd - $Hour) * 60.0;
78 $Sec = ($ddd - $Min) * 60.0;
88 $Retval = sprintf("%s%.0f\xB0%02.0f'%04.1f\"",
98 # Calculate current lat or lon position based on time.
99 # ta/tb = first/last time
100 # xa/xb = first/last position
101 # tc/xc = current time/position
103 # xc = xa+((xb-xa)*((tc-ta)/(tb-ta)))
105 my ($ta, $xa, $tb, $xb, $tc) = @_;
106 D
("current_pos('" . join("', '", @_) . "');");
107 my $xc = $xa+(($xb-$xa)*(($tc-$ta)/($tb-$ta)));
108 D
("current_pos() returns '$xc'");