/[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 23 by dpavlin, Thu Dec 6 14:03:00 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;  
   
 sub recalc {  
         my ( $lat, $lat_ns, $lon, $lon_ew ) = @_;  
   
         $lat = -$lat if $lat_ns eq 'S';  
         $lon = -$lon if $lon_ew eq 'W';  
14    
15          return if ( $got_it->{ $lat . $lon }++ );  my $trace_path = '/home/dpavlin/x/openmoko/gps/';
16    
17          $lat = deg( $lat ) || return;  # http://localhost/
18          $lon = deg( $lon ) || return;  my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';
19    
20          warn "## $lon $lat\n";  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( -id => 'trace_frm' ),
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                    -onChange => 'trace_frm.submit()',
45            ),
46            $q->submit( -value => 'Show trace' ),
47            $q->br,
48            'Draw as ',
49            $q->checkbox(
50                    -name => 'line',
51                    -onChange => 'trace_frm.submit()',
52            ),
53            ' with every ',
54            $q->textfield(
55                    -name => 'nth_placemark',
56                    -value => 5,
57                    -size => 2,
58                    -onChange => 'trace_frm.submit()',
59            ),
60            '<sup>th</sup> placemark',
61            $q->end_form,
62    );
63    
64    
65    my @points;
66    my $center_point;
67    
68    if ( my $trace = $q->param('trace') ) {
69            $trace =~ s/\s.+$//;
70    
71            my $map = HTML::GoogleMaps->new(key => $map_key);
72            #$map->center(point => "Zagreb, Hrvatska");
73    
74            $trace = "$trace_path/$trace";
75    
76            my $points = 0;
77            my $nth_placemark = $q->param('nth_placemark');
78    
79            open(my $fh, '<', $trace) || die "can't open $trace: $!";
80            while( <$fh> ) {
81    
82                    my $hash = NMEA->line( $_ ) || next;
83    
84                    my $point = [ $hash->{lon}, $hash->{lat} ];
85                    $center_point ||= $point;
86    
87    
88                    if ( $q->param('line') ) {
89                            push @points, $point;
90                    }
91    
92                    if ( ! $q->param('line') ||
93                            $nth_placemark && $points % $nth_placemark == 0
94                    ) {
95    
96                            $map->add_marker(
97                                    point => $point,
98                                    html => join('<br/>',
99                                            map {
100                                                    ucfirst($_) . ': ' . $hash->{$_}
101                                            } ( qw/time lat lon speed course/ )
102                                    ),
103                            );
104    
105          return [ $lon, $lat ];                  }
 }  
106    
107  open(my $fh, '<', $trace) || die "can't open $trace: $!";                  $points++;
 while( <$fh> ) {  
         if ( m/\$GPRMC/ ) {  
                 chomp;  
                 my @a = split(/,/,$_);  
108    
109                  next unless $#a = 12;          }
110            close($fh);
                 warn "## [$#a] $_\n";  
111    
112                  my ( undef, $time, $validity, $lat, $lat_ns, $lon, $lon_ew, $speed, $course, $date, $var, $var_ew ) = @a;          if ( $points > 0 ) {
113    
114                  next unless $validity eq 'A';                  #$map->zoom(10);
115                    #$map->v2_zoom(0);
116                    $map->controls("large_map_control", "map_type_control");
117                    $map->map_type('hybrid');
118                    $map->center( $center_point ) if $q->param('line') && $center_point;
119    
120                    if ( $q->param('line') ) {
121                            warn "## points = ",dump( @points );
122                            $map->add_polyline( points => [ @points ] );
123                    }
124    
125                  my $point = recalc( $lat, $lat_ns, $lon, $lon_ew ) || next;                  my ( $map_div, $map_script );
126                    ( $head, $map_div, $map_script ) = $map->render;
127    
128                  $map->add_marker(                  $html .= join('', qq{
129                          point => $point,  <h1>Plotting $points points from }, $q->param('trace'), qq{</h1>
130                          html => "Time: $time<br/>Validity: $validity</br>Lat: $lat $lat_ns<br/>Lon: $lon $lon_ew<br/>Speed: $speed<br/>Course: $course",  $map_div
131                  ) if $validity eq 'A';  $map_script
132    <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>
133                    });
134            
135            } else {
136                    $html .= '<em>No points found for ' . $q->param('trace') . '</em>';
137          }          }
 }  
 close($fh);  
138    
139  #$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;  
140    
 print "Content-type: text/html\n\r\n\r";  
141  print qq{  print qq{
142  <html>  <html>
143    <head>
144  <title>Read GPS - NMEA sentence and display it on GoogleMaps</title>  <title>Read GPS - NMEA sentence and display it on GoogleMaps</title>
145  <head>$head</head>  $head
146    </head>
147  <body>  <body>
148  $map_div  $html
   
 $map_script  
 <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>  
149  </body>  </body>
150  </html>  </html>
151  };  };

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

  ViewVC Help
Powered by ViewVC 1.1.26