| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Geo::Coder::Many::Ovi; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
63
|
|
|
4
|
2
|
|
|
2
|
|
11
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
58
|
|
|
5
|
2
|
|
|
2
|
|
53
|
use Carp; |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
108
|
|
|
6
|
2
|
|
|
2
|
|
11
|
use Geo::Coder::Many::Util; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
72
|
|
|
7
|
2
|
|
|
2
|
|
9
|
use base 'Geo::Coder::Many::Generic'; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
1365
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Geo::Coder::Many::Ovi - Ovi plugin Geo::Coder::Many |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.02 |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Requires Geo::Coder::Ovi 0.01 or above |
|
22
|
0
|
|
|
0
|
|
|
sub _MIN_MODULE_VERSION { return '0.01'; } |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This module adds Ovi support to Geo::Coder::Many. |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Use as follows: |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Geo::Coder::Many; |
|
31
|
|
|
|
|
|
|
use Geo::Coder::Ovi; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $options = { }; |
|
34
|
|
|
|
|
|
|
my $geocoder_many = Geo::Coder::Many->new( $options ); |
|
35
|
|
|
|
|
|
|
my $GCO = Geo::Coder::Ovi->new(); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $options = { |
|
38
|
|
|
|
|
|
|
geocoder => $GCO, |
|
39
|
|
|
|
|
|
|
}; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$geocoder_many->add_geocoder( $options ); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $location = $geocoder_many->geocode( |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
|
|
|
|
|
|
location => 'London EC1M 5RF, United Kingdom' |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 MORE INFO |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
please see http://search.cpan.org/dist/Geo-Coder-Ovi/ |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 geocode |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This is called by Geo::Coder::Many - it sends the geocoding request (via |
|
58
|
|
|
|
|
|
|
Geo::Coder::Ovi) and extracts the resulting location, returning it in a |
|
59
|
|
|
|
|
|
|
standard Geo::Coder::Many::Response. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Note: the precision score is set based on the size of the bounding box returned. |
|
62
|
|
|
|
|
|
|
Not all queries seem to return a bounding box. In that case precision in undef |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub geocode { |
|
67
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
68
|
0
|
|
|
|
|
|
my $location = shift; |
|
69
|
0
|
0
|
|
|
|
|
defined $location or croak "Geo::Coder::Many::Ovi::geocode |
|
70
|
|
|
|
|
|
|
method must be given a location."; |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my @raw_replies = $self->{GeoCoder}->geocode( location => $location ); |
|
73
|
0
|
|
|
|
|
|
my $response = Geo::Coder::Many::Response->new( { location => $location } ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
foreach my $raw_reply ( @raw_replies ) { |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $lng = undef; |
|
78
|
0
|
|
|
|
|
|
my $lat = undef; |
|
79
|
0
|
0
|
|
|
|
|
if (defined($raw_reply->{properties})){ |
|
80
|
0
|
|
|
|
|
|
$lat = $raw_reply->{properties}{geoLatitude}; |
|
81
|
0
|
|
|
|
|
|
$lng = $raw_reply->{properties}{geoLongitude}; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
0
|
0
|
|
|
|
if (defined($lng) && defined($lat)){ # did we get anything? |
|
85
|
0
|
|
|
|
|
|
my $precision = $self->_determine_precision($raw_reply); |
|
86
|
0
|
|
|
|
|
|
my $tmp = { |
|
87
|
|
|
|
|
|
|
address => $raw_reply->{title}, |
|
88
|
|
|
|
|
|
|
country => $raw_reply->{addrCountryName}, |
|
89
|
|
|
|
|
|
|
longitude => $lng, |
|
90
|
|
|
|
|
|
|
latitude => $lat, |
|
91
|
|
|
|
|
|
|
precision => $precision, |
|
92
|
|
|
|
|
|
|
}; |
|
93
|
0
|
|
|
|
|
|
$response->add_response( $tmp, $self->get_name() ); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $http_response = $self->{GeoCoder}->response(); |
|
98
|
0
|
|
|
|
|
|
$response->set_response_code($http_response->code()); |
|
99
|
0
|
|
|
|
|
|
return $response; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# return number between 0 and 1 |
|
103
|
|
|
|
|
|
|
sub _determine_precision { |
|
104
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
105
|
0
|
|
|
|
|
|
my $raw = shift; |
|
106
|
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
my $precision = undef; |
|
108
|
|
|
|
|
|
|
# if we have a bounding box we can calculate a precision |
|
109
|
0
|
0
|
0
|
|
|
|
if (defined($raw->{properties}) |
|
110
|
|
|
|
|
|
|
&& defined($raw->{properties}{geoBbxLatitude2}) |
|
111
|
|
|
|
|
|
|
){ |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$precision = |
|
114
|
|
|
|
|
|
|
Geo::Coder::Many::Util::determine_precision_from_bbox({ |
|
115
|
|
|
|
|
|
|
'lon1' => $raw->{properties}{geoBbxLongitude1}, |
|
116
|
|
|
|
|
|
|
'lat1' => $raw->{properties}{geoBbxLatitude1}, |
|
117
|
|
|
|
|
|
|
'lon2' => $raw->{properties}{geoBbxLongitude2}, |
|
118
|
|
|
|
|
|
|
'lat2' => $raw->{properties}{geoBbxLatitude2}, |
|
119
|
|
|
|
|
|
|
}); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
0
|
|
|
|
|
|
return $precision; |
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 get_name |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Returns the name of the geocoder type - used by Geo::Coder::Many |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=cut |
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
0
|
1
|
|
sub get_name { my $self = shift; return 'ovi ' . $self->{GeoCoder}->VERSION; } |
|
|
0
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |