|
Geo::Query::LatLong - Uniform interface to query latitude and longitude from a city. |
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:
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 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
|
Geo::Query::LatLong - Uniform interface to query latitude and longitude from a city. |