copied files for koha publisher geolocation
[google-map-tiles.git] / koha.pl
1 #!/usr/bin/perl
2 # Deliver click values to volcano.htm...
3 # Author. John D. Coryat 02/2010...
4 # Copyright 2010 USNaviguide LLC. All rights reserved...
5
6 use CGI qw/:standard *table/;
7 use strict ;
8 use DBI ;
9 use USNaviguide_Google_Tiles ;
10
11 my $dbh         = DBI->connect ( "dbi:Pg:dbname=volcano" , "" , "" , { AutoCommit => 1 } ) ;
12 my $point       = param('POINT') ;
13 my $zoom        = param('ZOOM') ;
14
15 my $lat         = 0 ;
16 my $lng         = 0 ;
17 my $latpix      = 0 ;
18 my $lngpix      = 0 ;
19
20 my $volpnt      = '' ;
21 my $vlat        = 0 ;
22 my $vlng        = 0 ;
23 my $vlatpix     = 0 ;
24 my $vlngpix     = 0 ;
25
26 my $value       = '' ;
27 my $maxpix      = 15 ;                                  # Maximum pixels between click and point
28 my $name        = '' ;
29 my $descript    = '' ;
30 my $x           = '' ;
31 my $i           = 0 ;
32
33 print header('text/xml');
34 print qq{<?xml version="1.0" encoding="UTF-8"?>\n} ;
35 print qq!<map>\n! ;
36
37 if ( !$point )
38 {
39  print qq!<info error="No point passed..."/>\n! ;
40  print qq!</map>\n! ;
41  $dbh->disconnect ;
42  exit ;
43 }
44
45 if ( $point =~ /(.*),(.*)/ )
46 {
47  $lat   = $1 ;
48  $lng   = $2 ;
49
50  $value = &Google_Tile_Factors($zoom) ;                                 # Calculate Tile Factors
51
52  ($latpix,$lngpix) = &Google_Coord_to_Pix( $value, $lat, $lng ) ;       # Convert coordinate to pixel location
53  
54  $x = "select name,descript,volpnt,point'($lat,$lng)' <-> volpnt as distance from gvp_world order by distance limit 1" ;
55
56  if ( ($name,$descript,$volpnt,$i) = $dbh->selectrow_array($x) )        # Got one
57  {
58   $volpnt =~ /\((.*),(.*)\)/ ; 
59   $vlat = $1 ;
60   $vlng = $2 ;
61
62   ($vlatpix,$vlngpix) = &Google_Coord_to_Pix( $value, $vlat, $vlng ) ;  # Convert coordinate to pixel location
63
64   if ( sqrt(($vlatpix - $latpix)**2  + ($vlngpix - $lngpix)**2) > $maxpix )
65   {
66    # Click not within maxpix of point...
67    print qq!<info error="No volcano is within range of your click, please try again."/>\n! ;
68   } else                                                                # Good point found
69   {
70    print qq!<info error = "" name = "$name" lat="$vlat" lng="$vlng">\n! ;
71    print qq! <description><\![CDATA[$descript]]></description>\n! ;
72    print qq!</info>\n! ;
73   }
74  }
75 } else
76 {
77  print qq!<info error="No valid point ($point) passed. Should be: (lat,lng) format."/>\n! ;
78 }
79 $dbh->disconnect ;
80
81 print "</map>\n\n" ;
82