Geo::Query::LatLong - Uniform interface to query latitude and longitude from a city.
use Geo::Query::LatLong; # Generic source $geo = Geo::Query::LatLong->new( debug => 0 );
or
# Using Google Maps API $geo = Geo::Query::LatLong->new( source => 'Google', apikey => 'Your API key' );
Query latitude and longitude from a city in any country. Useful to open specific locations in a Browser map. You can use a generic server or query the Google Maps API. In case of Google Maps you had to supply your Google key. Geo::Query::LatLong returns an uniform response independent of the chosen server.
use Geo::Query::LatLong; $CITY = $ARGV[0] || 'Zurich'; $res = $geo->query( city => $CITY, country_code => 'SZ' ); # FIPS 10 country code print "Latitude and longitude of $CITY: ", $res->{'lat'}, ' / ', $res->{'lng'}, "\n";
foreach (keys %{$res}) { print "$_ = ", $res->{$_}, "\n"; }
Switch exactness to "off" will increase the chance you get a result.
$res = $geo->query( city => 'Unterwalden', country_code => 'SZ', exact => 'off' ); # exact default: on print "-- $_ = ", $res->{$_}, "\n" foreach keys %{$res};
Country Codes according to FIPS 10: http://de.wikipedia.org/wiki/FIPS_10
Use the english translations for the city names, e.g. Zurich for Zuerich, Munich for Muenchen.
In conjunction with Google API you can send arguments like "Bellevue Zurich, Switzerland" as well.
The function query(...) always returns a hash reference. Hash key 'rc' is retured as 0 (Zero) on success and unequal 0 on a failure. Additionally it is a good advice to read or display the 'msg' key on a failure to get a hint about the cause.
On case the city was not found:
Hash key 'rc' returns a number unequal to zero.
Hash keys 'lat' / 'lng' are always being returned as '99' / '99'.
None by default.
http://meta.pgate.net/geo-query-latlong/
http://www.infocopter.com/perl/modules/
The Geo::Coder series here on CPAN.
Reto Schaer, <retoh@cpan-cuthere.org>
Copyright (C) 2007 - 2008 by Reto Schaer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
http://www.infocopter.com/perl/licencing.html
2 POD Errors
The following errors were encountered while parsing the POD:
'=item' outside of any '=over'
You forgot a '=back' before '=head2'
To install Geo::Query::LatLong, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Geo::Query::LatLong
CPAN shell
perl -MCPAN -e shell install Geo::Query::LatLong
For more information on module installation, please visit the detailed CPAN module installation guide.