You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/Geo/Coder/OpenCage.pm
+51-23Lines changed: 51 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -144,6 +144,11 @@ __END__
144
144
145
145
=encodingutf8
146
146
147
+
148
+
=head1NAME
149
+
150
+
Geo::Coder::OpenCage - Perl interface to the OpenCage geocoding API
151
+
147
152
=head1DESCRIPTION
148
153
149
154
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|
156
161
157
162
my $Geocoder = Geo::Coder::OpenCage->new(api_key => $my_api_key);
158
163
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
+
=head1DEVELOPING 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.
160
184
161
185
=head1METHODS
162
186
@@ -166,7 +190,7 @@ It is recommended you read the L<best practices for using the OpenCage geocoder|
166
190
167
191
Get your API key from L<https://opencagedata.com>.
168
192
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.
170
194
171
195
=head2ua
172
196
@@ -175,8 +199,9 @@ Optionally "http => 1" can also be specified in which case API requests will NOT
175
199
176
200
Accessor for the UserAgent object. By default HTTP::Tiny is used. Useful if for
177
201
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.
180
205
181
206
=head2geocode
182
207
@@ -198,16 +223,23 @@ Please see the
198
223
L<OpenCage geocoding API response codes|https://opencagedata.com/api#codes>
199
224
200
225
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
+
}
202
233
203
-
=over1
204
234
205
235
=itemSupported Parameters
206
236
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.
209
240
210
-
=over2
241
+
242
+
The most commonly useful parameters are:
211
243
212
244
=itemlanguage
213
245
@@ -224,30 +256,26 @@ Provides the geocoder with a hint to the country that the query resides in.
224
256
This value will help the geocoder but will not restrict the possible results to
225
257
the supplied country.
226
258
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.
0 commit comments