line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Many::PlaceFinder; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
58
|
|
5
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
113
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
11
|
use Geo::Coder::Many::Generic; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
234
|
|
8
|
2
|
|
|
2
|
|
11
|
use Geo::Coder::Many::Util; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
131
|
|
9
|
2
|
|
|
2
|
|
10
|
use base 'Geo::Coder::Many::Generic'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1050
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Geo::Coder::Many::PlaceFinder - Yahoo PlaceFinder plugin for Geo::Coder::Many |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.03 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Requires Geo::Coder::PlaceFinder 0.02 or above |
24
|
0
|
|
|
0
|
|
|
sub _MIN_MODULE_VERSION { return '0.02'; } |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This module adds Yahoo PlaceFinder support to Geo::Coder::Many. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Use as follows: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Geo::Coder::Many; |
33
|
|
|
|
|
|
|
use Geo::Coder::PlaceFinder; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $options = { }; |
36
|
|
|
|
|
|
|
my $geocoder_many = Geo::Coder::Many->new( $options ); |
37
|
|
|
|
|
|
|
my $place_finder = Geo::Coder::PlaceFinder->new( appid => 'YOUR_APP_ID' ); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my $place_finder_options = { |
40
|
|
|
|
|
|
|
geocoder => $place_finder, |
41
|
|
|
|
|
|
|
daily_limit => 50000, |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$geocoder_many->add_geocoder( $place_finder_options ); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $location = $geocoder_many->geocode( |
47
|
|
|
|
|
|
|
{ |
48
|
|
|
|
|
|
|
location => '82 Clerkenwell Road, London, EC1M 5RF' |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 USAGE POLICY |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
As of writing, Yahoo PlaceFinder allows up to 50000 requests per day. This may |
55
|
|
|
|
|
|
|
change, so you should check the latest documentation to make sure you aren't |
56
|
|
|
|
|
|
|
going to get blocked. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
http://developer.yahoo.com/geo/placefinder/ |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 geocode |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
This is called by Geo::Coder::Many - it sends the geocoding request (via |
65
|
|
|
|
|
|
|
Geo::Coder::PlaceFinder) and extracts the resulting location, returning it in a |
66
|
|
|
|
|
|
|
standard Geo::Coder::Many::Response. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub geocode { |
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
my $location = shift; |
73
|
0
|
0
|
|
|
|
|
defined $location or croak "geocode method must be given a location\n"; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my @raw_replies = $self->{GeoCoder}->geocode( location => $location ); |
76
|
0
|
|
|
|
|
|
my $response = Geo::Coder::Many::Response->new( { location => $location } ); |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $http_response = $self->{GeoCoder}->response(); |
79
|
0
|
|
|
|
|
|
my $location_data = []; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
foreach my $raw_reply ( @raw_replies ) { |
82
|
0
|
|
|
|
|
|
my @address_lines = @{$raw_reply}{'line1', 'line2', 'line3', 'line4'}; |
|
0
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
@address_lines = grep {!/^\s*$/x} @address_lines; |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $address = (join ', ', @address_lines); |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $precision = 0; |
88
|
0
|
0
|
|
|
|
|
if (defined($raw_reply->{boundingbox})){ |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
my $box = $raw_reply->{boundingbox}; |
91
|
|
|
|
|
|
|
# lng and lat in decimal degree format |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$precision = |
94
|
|
|
|
|
|
|
Geo::Coder::Many::Util::determine_precision_from_bbox({ |
95
|
|
|
|
|
|
|
'lon1' => $box->{west}, |
96
|
|
|
|
|
|
|
'lat1' => $box->{south}, |
97
|
|
|
|
|
|
|
'lon2' => $box->{east}, |
98
|
|
|
|
|
|
|
'lat2' => $box->{north}, |
99
|
|
|
|
|
|
|
}); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
my $tmp = { |
103
|
|
|
|
|
|
|
address => $address, |
104
|
|
|
|
|
|
|
country => $raw_reply->{country}, |
105
|
|
|
|
|
|
|
longitude => $raw_reply->{longitude}, |
106
|
|
|
|
|
|
|
latitude => $raw_reply->{latitude}, |
107
|
|
|
|
|
|
|
precision => $precision, |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
$response->add_response( $tmp, $self->get_name() ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$response->set_response_code($http_response->code()); |
114
|
0
|
|
|
|
|
|
return $response; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 get_name |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns the name of the geocoder type - used by Geo::Coder::Many |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
0
|
1
|
|
sub get_name { my $self = shift; return 'place_finder ' . $self->{GeoCoder}->VERSION; }; |
|
0
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
1; # End of Geo::Coder::Many::PlaceFinder |