Geo::Yandex - Performs geographical queries using Yandex Maps API
use Geo::Yandex; # Address to search my $addr = 'Москва, Красная площадь, 1'; # Personal API key, should be obtained at http://api.yandex.ru/maps/form.xml my $key = '. . .'; # New geo object, note to use the key my $geo = new Geo::Yandex($key); # Search locations with a given address my @locations = $geo->location(address => $addr); # Or specify query in more details my @locations = $geo->location( address => $addr, results => 3, skip => 2, center => '37.618920,55.756994', size => '0.552069,0.400552' ); # Locations are an array of Geo::Yandex::Location elements for my $item (@locations) { say $item->address . ' (' . $item->kind .') ' . $item->latitude . ',' . $item->longitude; }
Geo::Yandex is a Perl interface for the part of Yandex Maps API which retrieves geographical data for text query.
Yandex Maps API is a set of tools for working with http://maps.yandex.ru website both with JavaScript queries and HTTP negotiations. Full description of the interface can be found at http://api.yandex.ru/maps/doc/ (in Russian).
All the work is done by an instance of Geo::Yandex class.
Creates a new Geo::Yandex object. The only argument, which is required, is a personal key that should be issued by Yandex before using API. To obtain the key you need to fill the form at http://api.yandex.ru/maps/form.xml.
my $geo = new Geo::Yandex($key);
Launches search query to Yandex and returns the list of locations which match to the given address (passed in address parameter).
address
my @locations = $geo->location(address => $addr);
The list returned by this method is combined of elements of the type Geo::Yandex::Location. If no results were found, return is an empty list.
This is the only parameter which is requered for performing the search. It is a text string containing the address of the location being searched. May be in less or more free form.
Optional parameter which sets the limit of search. No more results will appear than a number set by this parameter.
Optional parameter to skip several first results. Useful in pair with results parameter for organizing paginated output.
results
my @locations = $geo->location( address => $addr, center => '37.618920,55.756994', size => '0.552069,0.400552' );
These two parameters restrict the search area with a boundary located withing (longitude, latitude) pair set in center. This point will be located in the center of search area. To set width and height of the search block use size parameter. Both parameters are optional. Each should contain a pair of numbers (geographical measure - degree) separated by a comma.
center
size
Please note that you should not expect that center and size parameters will bring rigid boundaries of the area; those are just hints for the search engine. Seems to be weird stuff.
Andrew Shitov, <andy@shitov.ru>
Geo::Yandex module is a free software. You may redistribute and (or) modify it under the same terms as Perl, whichever version it is.
To install Geo::Yandex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Geo::Yandex
CPAN shell
perl -MCPAN -e shell install Geo::Yandex
For more information on module installation, please visit the detailed CPAN module installation guide.