#!/usr/bin/perl use strict; use warnings; use lib qw(/home/greg/data/prog/lib); use lib qw(/home/greg/data/prog/dist/rdf-query/lib); use lib qw(/home/greg/data/prog/dist/geo-lookup/lib); use CGI; use IO::All; use File::Spec; use URI::Escape; use Data::Dumper; use RDF::Redland; use Geo::Distance; use POSIX qw(ceil floor); use Kasei::RDF::Gallery qw(generate_gallery); use Kasei::RDF::Common qw(mysql_model fill_template get_first_uri get_first_literal); my $base_uri = 'http://kasei.us'; my $base_local = '/home/greg/www'; my $index_uri = "${base_uri}/e/locations/index.cgi"; my $near_uri = "${base_uri}/e/locations/near.cgi"; my $in_uri = "${base_uri}/e/locations/in.cgi"; our $debug = 0; ###################################################################### main(); sub main { my $l = new Location::Name; my $q = new CGI; my $page = $q->param('page') || 1; my $ipp = $q->param('ipp') || 15; my $miles = $q->param('miles') || 20; my ($name, $lat, $lon); if (my $keywords = $q->param('keywords')) { my ($x, $y) = split(/,/, $q->param('keywords')); warn "[$x, $y]" if ($debug); $lat = sprintf("%.4f", 90 - (($y / 518) * 180)); $lon = sprintf("%.4f", (($x / 1036) * 360) - 180); $q->param('searchtype', 'near'); } elsif ($name = $q->param('name')) { my ($loc) = $l->position( $name ); if ($loc) { ($lat, $lon) = @{ $loc }[0,1]; } else { warn "No location data found for '$name'.\n"; warn Dumper($loc) if ($debug); } } else { $lat = $q->param('lat'); $lon = $q->param('lon'); } if ($lat and $lon) { if (my $type = $q->param('searchtype')) { if ($type eq 'in') { print $q->redirect( sprintf("${in_uri}?name=%s&ipp=${ipp}&page=${page}", uri_escape($name)) ); } else { print $q->redirect( "${near_uri}?lat=${lat}&lon=${lon}&ipp=${ipp}&miles=${miles}&page=${page}" ); } } else { print $q->redirect( "${near_uri}?lat=${lat}&lon=${lon}&ipp=${ipp}&miles=${miles}&page=${page}" ); } } else { print $q->header( -charset => 'utf-8' ); print <<"END" Location

within (only on "Near" searches)

END } } ###################################################################### __END__