--- web/googlemap.cgi 2007/12/02 19:05:29 13 +++ web/googlemap.cgi 2007/12/03 14:25:40 14 @@ -4,86 +4,94 @@ use strict; use HTML::GoogleMaps; +use CGI; use CGI::Carp qw/fatalsToBrowser/; +use File::Find; use Data::Dump qw/dump/; -# http://localhost/ -my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg'; - -my $trace = '/home/dpavlin/x/openmoko/gps/foo.loc'; - -my $map = HTML::GoogleMaps->new(key => $map_key); -#$map->center(point => "Zagreb, Hrvatska"); - -sub deg { - my $a = shift; - if ( $a =~ m/^(\d+)(\d\d\.\d\d+)$/ ) { - return sprintf("%1.6f", $1 + ( $2 / 60 )); - } else { - warn "## skipped $a\n"; - return; - } -} +use lib '../'; +use NMEA; -my $got_it; +my $trace_path = '/home/dpavlin/x/openmoko/gps/'; -sub recalc { - my ( $lat, $lat_ns, $lon, $lon_ew ) = @_; - - $lat = -$lat if $lat_ns eq 'S'; - $lon = -$lon if $lon_ew eq 'W'; - - return if ( $got_it->{ $lat . $lon }++ ); - - $lat = deg( $lat ) || return; - $lon = deg( $lon ) || return; +# http://localhost/ +my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg'; - warn "## $lon $lat\n"; +my @traces; +find({ wanted => sub { + push @traces, $_ if -f $_; +}}, $trace_path); - return [ $lon, $lat ]; -} +my $q = CGI->new; -open(my $fh, '<', $trace) || die "can't open $trace: $!"; -while( <$fh> ) { - if ( m/\$GPRMC/ ) { - chomp; - my @a = split(/,/,$_); +print $q->header; - next unless $#a = 12; +print qq{ + +Read GPS - NMEA sentence and display it on GoogleMaps + +

Select GPS NMEA dump

+ }, + $q->start_form, + $q->popup_menu( + -name => 'trace', + -values => [ + map { + "$_ (" . (stat("$trace_path/$_"))[7] . " bytes)" + } + sort { + (stat("$trace_path/$a"))[10] <=> (stat("$trace_path/$b"))[10] + } @traces + ], + ), + $q->submit( -value => 'Show trace' ), + $q->end_form; + +if ( my $trace = $q->param('trace') ) { + $trace =~ s/\s.+$//; + + my $map = HTML::GoogleMaps->new(key => $map_key); + #$map->center(point => "Zagreb, Hrvatska"); - warn "## [$#a] $_\n"; + $trace = "$trace_path/$trace"; - my ( undef, $time, $validity, $lat, $lat_ns, $lon, $lon_ew, $speed, $course, $date, $var, $var_ew ) = @a; + my $points = 0; - next unless $validity eq 'A'; + open(my $fh, '<', $trace) || die "can't open $trace: $!"; + while( <$fh> ) { - my $point = recalc( $lat, $lat_ns, $lon, $lon_ew ) || next; + my $hash = NMEA->line( $_ ) || next; $map->add_marker( - point => $point, - html => "Time: $time
Validity: $validity
Lat: $lat $lat_ns
Lon: $lon $lon_ew
Speed: $speed
Course: $course", - ) if $validity eq 'A'; + point => [ $hash->{lon}, $hash->{lat} ], + html => join('
', + map { + ucfirst($_) . ': ' . $hash->{$_} + } ( qw/time lat lon speed course/ ) + ), + ); + + $points++; } -} -close($fh); + close($fh); -#$map->zoom(10); -#$map->v2_zoom(0); -$map->controls("large_map_control", "map_type_control"); -$map->map_type('hybrid'); + #$map->zoom(10); + #$map->v2_zoom(0); + $map->controls("large_map_control", "map_type_control"); + $map->map_type('hybrid'); -my ($head, $map_div, $map_script) = $map->render; + my ($head, $map_div, $map_script) = $map->render; -print "Content-type: text/html\n\r\n\r"; -print qq{ - -Read GPS - NMEA sentence and display it on GoogleMaps -$head - + print qq{ +

Plotting $points points from }, $q->param('trace'), qq{

$map_div - $map_script GPS - NMEA sentence information + }; + +} + +print qq{ };