Skip to content

Commit 44d8153

Browse files
committed
pod improvements for v0.37
1 parent b418de4 commit 44d8153

File tree

2 files changed

+54
-24
lines changed

2 files changed

+54
-24
lines changed

Changes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Revision history for Geo-Coder-OpenCage
22

3-
0.37 YYYY-MM-DD
3+
0.37 2025-03-26
4+
- pod improvements/clarifications, including mention of relevant AI SKILL
5+
no code changes
46

57
0.36 2023-03-14
68
- pod improvements/clarifications, no code changes

lib/Geo/Coder/OpenCage.pm

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ __END__
144144
145145
=encoding utf8
146146
147+
148+
=head1 NAME
149+
150+
Geo::Coder::OpenCage - Perl interface to the OpenCage geocoding API
151+
147152
=head1 DESCRIPTION
148153
149154
This module provides an interface to the OpenCage geocoding service.
@@ -156,7 +161,26 @@ It is recommended you read the L<best practices for using the OpenCage geocoder|
156161
157162
my $Geocoder = Geo::Coder::OpenCage->new(api_key => $my_api_key);
158163
159-
my $response = $Geocoder->geocode(location => "Donostia");
164+
# forward geocoding
165+
my $response = $Geocoder->geocode(location => "Berlin");
166+
167+
# reverse geocoding
168+
my $response = $geocoder->reverse_geocode(lat => 52.5432379, lng => 13.4142133 );
169+
170+
if ($response->{status}{code} == 200) {
171+
foreach my $r (@{ $response->{results} }) {
172+
print $r->{formatted}, "\n";
173+
print 'lat: ' . $r->{geometry}{lat}, "\n";
174+
print 'lng: ' . $r->{geometry}{lng}, "\n";
175+
}
176+
}
177+
178+
179+
=head1 DEVELOPING WITH AI
180+
181+
Please note there is an
182+
L<AI SKILL.md for working with the OpenCage Geocoding API|https://github.com/OpenCageData/opencage-skills/blob/master/opencage-geocoding-api/SKILL.md>
183+
which includes a reference file for developing in Perl using this module.
160184
161185
=head1 METHODS
162186
@@ -166,7 +190,7 @@ It is recommended you read the L<best practices for using the OpenCage geocoder|
166190
167191
Get your API key from L<https://opencagedata.com>.
168192
169-
Optionally "http => 1" can also be specified in which case API requests will NOT be made via https
193+
Optionally "http => 1" can also be specified in which case API requests will NOT be made via https.
170194
171195
=head2 ua
172196
@@ -175,8 +199,9 @@ Optionally "http => 1" can also be specified in which case API requests will NOT
175199
176200
Accessor for the UserAgent object. By default HTTP::Tiny is used. Useful if for
177201
example you want to specify that something like LWP::UserAgent::Throttled for
178-
rate limiting. Even if a new UserAgent is specified the useragent string will
179-
be specified as "Geo::Coder::OpenCage $version"
202+
rate limiting.
203+
204+
Regardless of which UserAgent object is used, the User-Agent HTTP header will always be set to Geo::Coder::OpenCage/$version.
180205
181206
=head2 geocode
182207
@@ -198,16 +223,23 @@ Please see the
198223
L<OpenCage geocoding API response codes|https://opencagedata.com/api#codes>
199224
200225
201-
The OpenCage Geocoder has a few optional parameters:
226+
my $response = $geocoder->geocode(location => "Berlin");
227+
unless (defined $response) {
228+
die "Geocoding failed";
229+
}
230+
if ($response->{status}{code} != 200) {
231+
warn "API error: " . $result->{status}{message};
232+
}
202233
203-
=over 1
204234
205235
=item Supported Parameters
206236
207-
please see L<the OpenCage geocoder documentation|https://opencagedata.com/api>. Most of
208-
L<the various optional parameters|https://opencagedata.com/api#forward-opt> are supported. For example:
237+
The OpenCage Geocoder has a few optional parameters.
238+
239+
Please see L<the OpenCage geocoder documentation|https://opencagedata.com/api>. Most of L<the various optional parameters|https://opencagedata.com/api#forward-opt> are supported.
209240
210-
=over 2
241+
242+
The most commonly useful parameters are:
211243
212244
=item language
213245
@@ -224,30 +256,26 @@ Provides the geocoder with a hint to the country that the query resides in.
224256
This value will help the geocoder but will not restrict the possible results to
225257
the supplied country.
226258
227-
The country code is a comma seperated list of 2 character code as defined by the ISO 3166-1 Alpha 2 standard.
259+
The countrycode is a comma separated list of 2 character code as defined by the ISO 3166-1 Alpha 2 standard.
228260
229-
=back
261+
As a full example:
262+
263+
my $response = $Geocoder->geocode(
264+
location => "Псковская улица, Санкт-Петербург, Россия",
265+
language => "ru",
266+
countrycode => "ru",
267+
);
230268
231-
=item Not Supported
232269
233-
=over 2
270+
=item Not Supported
234271
235272
=item jsonp
236273
237274
This module always parses the response as a Perl data structure, so the jsonp
238275
option is never used.
239276
240-
=back
241-
242-
=back
277+
All other API parameters are passed through directly
243278
244-
As a full example:
245-
246-
my $response = $Geocoder->geocode(
247-
location => "Псковская улица, Санкт-Петербург, Россия",
248-
language => "ru",
249-
countrycode => "ru",
250-
);
251279
252280
=head2 reverse_geocode
253281

0 commit comments

Comments
 (0)