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

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

  ViewVC Help
Powered by ViewVC 1.1.26