| 1 | #!/usr/bin/perl -w | ||
| 2 | # | ||
| 3 | # $Id: sample.pl 255 2008-06-21 03:48:46Z dan $ | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use Geo::Hashing; | ||
| 7 | |||
| 8 | # get the date from the commandline, or assume it's today's date | ||
| 9 | my $date = shift || | ||
| 10 | sprintf("%04d-%02d-%02d", (localtime)[5]+1900, | ||
| 11 | (localtime)[4]+1, | ||
| 12 | (localtime)[3]); | ||
| 13 | |||
| 14 | die "Usage: $0 <date> [<lat,lon>]" | ||
| 15 | unless $date and $date =~ /^\d\d\d\d-\d\d-\d\d$/; | ||
| 16 | |||
| 17 | my ($lat, $lon) = (0, 0); | ||
| 18 | if (@ARGV) { | ||
| 19 | ($lat, $lon) = split /\s*,\s*/, "@ARGV"; | ||
| 20 | } | ||
| 21 | |||
| 22 | die "Invalid Lat/Lon!" unless $lat =~ /^-?\d+$/ and $lon =~ /^-?\d+$/; | ||
| 23 | |||
| 24 | my $geo = new Geo::Hashing(lat => $lat, lon => $lon, date => $date); | ||
| 25 | print "30W rule is in effect\n" if $geo->use_30w_rule; | ||
| 26 | printf "Geohash for $date ($lat, $lon): %0.6f, %0.6f\n", $geo->lat, $geo->lon; | ||
| 27 |