Geo::Coder::OpenCage
version 0.14
my $Geocoder = Geo::Coder::OpenCage->new(api_key => $my_api_key); my $result = $Geocoder->geocode(location => "Donostia");
This module provides an interface to the OpenCage geocoding service.
For full details of the API visit https://geocoder.opencagedata.com/api.
Geo::Coder::OpenCage - Geocode coordinates and addresses with the OpenCage Geocoder
my $Geocoder = Geo::Coder::OpenCage->new(api_key => $my_api_key);
Get your API key from https://geocoder.opencagedata.com
Takes a single named parameter 'location' and returns a result hashref.
my $result = $Geocoder->geocode(location => "Mudgee, Australia");
warns and returns undef if the query fails for some reason.
The OpenCage Geocoder has a few optional parameters
please see the OpenCage geocoder documentation. Most of the various optional parameters are supported. For example:
An IETF format language code (such as es for Spanish or pt-BR for Brazilian Portuguese); if this is omitted a code of en (English) will be assumed.
Limits the maximum number of results returned. Default is 10.
Provides the geocoder with a hint to the country that the query resides in. This value will help the geocoder but will not restrict the possible results to the supplied country.
The country code is a comma seperated list of 2 character code as defined by the ISO 3166-1 Alpha 2standard.
This module always parses the response as a Perl data structure, so the jsonp option is never used.
As a full example:
my $result = $Geocoder->geocode( location => "Псковская улица, Санкт-Петербург, Россия", language => "ru", countrycode => "ru", );
Takes two named parameters 'lat' and 'lng' and returns a result hashref.
my $result = $Geocoder->reverse_geocode(lat => -22.6792, lng => 14.5272);
This method supports the optional parameters in the same way that geocode() does.
All strings passed to and recieved from Geo::Coder::OpenCage methods are expected to be character strings, not byte strings.
For more information see perlunicode.
This module was featured in the 2016 Perl Advent Calendar. Read the article.
Ed Freyfogle
Copyright 2017 OpenCage Data Ltd <cpan@opencagedata.com>
Please check out all our open source work over at https://github.com/opencagedata and our developer blog: https://blog.opencagedata.com
Thanks!
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16 or, at your option, any later version of Perl 5 you may have available.
edf <edf@opencagedata.com>
This software is copyright (c) 2017 by OpenCage Data Limited.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Geo::Coder::OpenCage, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Geo::Coder::OpenCage
CPAN shell
perl -MCPAN -e shell install Geo::Coder::OpenCage
For more information on module installation, please visit the detailed CPAN module installation guide.