/[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

Annotation of /web/googlemap.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 18 - (hide annotations)
Mon Dec 3 15:06:33 2007 UTC (11 years, 5 months ago) by dpavlin
File size: 2039 byte(s)
don't show map (which in turns create JavaScript error) if there are no points
1 dpavlin 13 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     use HTML::GoogleMaps;
7 dpavlin 14 use CGI;
8 dpavlin 13 use CGI::Carp qw/fatalsToBrowser/;
9 dpavlin 14 use File::Find;
10 dpavlin 13 use Data::Dump qw/dump/;
11    
12 dpavlin 14 use lib '../';
13     use NMEA;
14    
15     my $trace_path = '/home/dpavlin/x/openmoko/gps/';
16    
17 dpavlin 13 # http://localhost/
18     my $map_key = 'ABQIAAAAVQ5szt9Jd8ws6vgfVQOEmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQ1cKf0DwFJcwtpESJEI0hL8QgtYg';
19    
20 dpavlin 14 my @traces;
21     find({ wanted => sub {
22     push @traces, $_ if -f $_;
23     }}, $trace_path);
24 dpavlin 13
25 dpavlin 14 my $q = CGI->new;
26 dpavlin 13
27 dpavlin 14 print $q->header;
28 dpavlin 13
29 dpavlin 15 my $head = '';
30     my $html = join('', qq{
31 dpavlin 14 <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 dpavlin 15 $q->end_form,
47     );
48 dpavlin 13
49 dpavlin 14 if ( my $trace = $q->param('trace') ) {
50     $trace =~ s/\s.+$//;
51 dpavlin 13
52 dpavlin 14 my $map = HTML::GoogleMaps->new(key => $map_key);
53     #$map->center(point => "Zagreb, Hrvatska");
54 dpavlin 13
55 dpavlin 14 $trace = "$trace_path/$trace";
56 dpavlin 13
57 dpavlin 14 my $points = 0;
58 dpavlin 13
59 dpavlin 14 open(my $fh, '<', $trace) || die "can't open $trace: $!";
60     while( <$fh> ) {
61 dpavlin 13
62 dpavlin 14 my $hash = NMEA->line( $_ ) || next;
63 dpavlin 13
64 dpavlin 14 $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 dpavlin 13
73 dpavlin 14 $points++;
74     }
75     close($fh);
76 dpavlin 13
77 dpavlin 18 if ( $points > 0 ) {
78 dpavlin 13
79 dpavlin 18 #$map->zoom(10);
80     #$map->v2_zoom(0);
81     $map->controls("large_map_control", "map_type_control");
82     $map->map_type('hybrid');
83 dpavlin 13
84 dpavlin 18 my ( $map_div, $map_script );
85     ( $head, $map_div, $map_script ) = $map->render;
86    
87     $html .= join('', qq{
88 dpavlin 14 <h1>Plotting $points points from }, $q->param('trace'), qq{</h1>
89     $map_div
90     $map_script
91     <a href="http://aprs.gids.nl/nmea/">GPS - NMEA sentence information</a>
92 dpavlin 18 });
93    
94     } else {
95     $html .= '<em>No points found for ' . $q->param('trace') . '</em>';
96     }
97 dpavlin 13
98     }
99    
100     print qq{
101 dpavlin 15 <html>
102     <head>
103     <title>Read GPS - NMEA sentence and display it on GoogleMaps</title>
104     $head
105     </head>
106     <body>
107     $html
108 dpavlin 13 </body>
109     </html>
110     };

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26