/[maps]/web/googlemap.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /web/googlemap.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 13 by dpavlin, Sun Dec 2 19:05:29 2007 UTC revision 15 by dpavlin, Mon Dec 3 14:47:08 2007 UTC
# Line 4  use warnings; Line 4  use warnings;
4  use strict;  use strict;
5    
6  use HTML::GoogleMaps;  use HTML::GoogleMaps;
7    use CGI;
8  use CGI::Carp qw/fatalsToBrowser/;  use CGI::Carp qw/fatalsToBrowser/;
9    use File::Find;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
11    
12  # http://localhost/  use lib '../';
13  my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';  use NMEA;
   
 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;  
         }  
 }  
   
 my $got_it;  
14    
15  sub recalc {  my $trace_path = '/home/dpavlin/x/openmoko/gps/';
         my ( $lat, $lat_ns, $lon, $lon_ew ) = @_;  
16    
17          $lat = -$lat if $lat_ns eq 'S';  # http://localhost/
18          $lon = -$lon if $lon_ew eq 'W';  my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';
19    
20          return if ( $got_it->{ $lat . $lon }++ );  my @traces;
21    find({ wanted => sub {
22            push @traces, $_ if -f $_;
23    }}, $trace_path);
24    
25    my $q = CGI->new;
26    
27    print $q->header;
28    
29    my $head = '';
30    my $html = join('', qq{
31    <h1>Select GPS NMEA dump</h1>
32            },
33            $q->start_form,
34            $q->popup_menu(
35                    -name => 'trace',
36                    -values => [
37                            map {
38                                    "$_ (" . (stat("$trace_path/$_"))[7] . " bytes)"
39                            }
40                            sort {
41                                    (stat("$trace_path/$a"))[10] <=> (stat("$trace_path/$b"))[10]
42                            } @traces
43                    ],
44            ),
45            $q->submit( -value => 'Show trace' ),
46            $q->end_form,
47    );
48    
49    if ( my $trace = $q->param('trace') ) {
50            $trace =~ s/\s.+$//;
51    
52            my $map = HTML::GoogleMaps->new(key => $map_key);
53            #$map->center(point => "Zagreb, Hrvatska");
54    
55          $lat = deg( $lat ) || return;          $trace = "$trace_path/$trace";
         $lon = deg( $lon ) || return;  
56    
57          warn "## $lon $lat\n";          my $points = 0;
58    
59          return [ $lon, $lat ];          open(my $fh, '<', $trace) || die "can't open $trace: $!";
60  }          while( <$fh> ) {
61    
62  open(my $fh, '<', $trace) || die "can't open $trace: $!";                  my $hash = NMEA->line( $_ ) || next;
 while( <$fh> ) {  
         if ( m/\$GPRMC/ ) {  
                 chomp;  
                 my @a = split(/,/,$_);  
63    
64                  next unless $#a = 12;                  $map->add_marker(
65                            point => [ $hash->{lon}, $hash->{lat} ],
66                            html => join('<br/>',
67                                    map {
68                                            ucfirst($_) . ': ' . $hash->{$_}
69                                    } ( qw/time lat lon speed course/ )
70                            ),
71                    );
72    
73                  warn "## [$#a] $_\n";                  $points++;
74            }
75            close($fh);
76    
77                  my ( undef, $time, $validity, $lat, $lat_ns, $lon, $lon_ew, $speed, $course, $date, $var, $var_ew ) = @a;          #$map->zoom(10);
78            #$map->v2_zoom(0);
79            $map->controls("large_map_control", "map_type_control");
80            $map->map_type('hybrid');
81    
82                  next unless $validity eq 'A';          my ( $map_div, $map_script );
83            ( $head, $map_div, $map_script ) = $map->render;
84    
85                  my $point = recalc( $lat, $lat_ns, $lon, $lon_ew ) || next;          $html .= join('', qq{
86    <h1>Plotting $points points from }, $q->param('trace'), qq{</h1>
87    $map_div
88    $map_script
89    <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>
90            });
91    
                 $map->add_marker(  
                         point => $point,  
                         html => "Time: $time<br/>Validity: $validity</br>Lat: $lat $lat_ns<br/>Lon: $lon $lon_ew<br/>Speed: $speed<br/>Course: $course",  
                 ) if $validity eq 'A';  
         }  
92  }  }
 close($fh);  
93    
 #$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;  
   
 print "Content-type: text/html\n\r\n\r";  
94  print qq{  print qq{
95  <html>  <html>
96    <head>
97  <title>Read GPS - NMEA sentence and display it on GoogleMaps</title>  <title>Read GPS - NMEA sentence and display it on GoogleMaps</title>
98  <head>$head</head>  $head
99    </head>
100  <body>  <body>
101  $map_div  $html
   
 $map_script  
 <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>  
102  </body>  </body>
103  </html>  </html>
104  };  };

Legend:
Removed from v.13  
changed lines
  Added in v.15

  ViewVC Help
Powered by ViewVC 1.1.26