line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Many::OSM; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
5
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
115
|
|
6
|
2
|
|
|
2
|
|
11
|
use Geo::Coder::Many::Util; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
7
|
2
|
|
|
2
|
|
9
|
use base 'Geo::Coder::Many::Generic'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
931
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Geo::Coder::Many::OSM - OpenStreetMap Nominatim plugin for 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::OSM 0.01 or above |
22
|
0
|
|
|
0
|
|
|
sub _MIN_MODULE_VERSION { return '0.01'; } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This module adds OpenStreetMap Nominatim support to Geo::Coder::Many. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Use as follows: |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Geo::Coder::Many; |
31
|
|
|
|
|
|
|
use Geo::Coder::OSM; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $options = { }; |
34
|
|
|
|
|
|
|
my $geocoder_many = Geo::Coder::Many->new( $options ); |
35
|
|
|
|
|
|
|
my $osm = Geo::Coder::OSM->new; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $osm_options = { |
38
|
|
|
|
|
|
|
geocoder => $osm, |
39
|
|
|
|
|
|
|
# This limit should not be taken as necessarily valid. |
40
|
|
|
|
|
|
|
# Please check the Nominatim usage policy. |
41
|
|
|
|
|
|
|
daily_limit => 5000, |
42
|
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$geocoder_many->add_geocoder( $osm_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
|
|
|
|
|
|
|
Be careful to limit the number of requests you send, or risk being blocked. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
See http://wiki.openstreetmap.org/wiki/Nominatim#Usage_Policy for details. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 geocode |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This is called by Geo::Coder::Many - it sends the geocoding request (via |
63
|
|
|
|
|
|
|
Geo::Coder::OSM) and extracts the resulting location, returning it in a |
64
|
|
|
|
|
|
|
standard Geo::Coder::Many::Response. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub geocode { |
69
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
my $location = shift; |
71
|
0
|
0
|
|
|
|
|
defined $location or croak "Geo::Coder::Many::OSM::geocode |
72
|
|
|
|
|
|
|
method must be given a location."; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my @raw_replies = $self->{GeoCoder}->geocode( location => $location ); |
75
|
0
|
|
|
|
|
|
my $response = Geo::Coder::Many::Response->new( { location => $location } ); |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $location_data = []; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
foreach my $raw_reply ( @raw_replies ) { |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $precision = 0; # unknown |
82
|
0
|
0
|
|
|
|
|
if (defined($raw_reply->{boundingbox})){ |
83
|
0
|
|
|
|
|
|
my $ra_bbox = $raw_reply->{boundingbox}; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$precision = |
86
|
|
|
|
|
|
|
Geo::Coder::Many::Util::determine_precision_from_bbox({ |
87
|
|
|
|
|
|
|
'lon1' => $ra_bbox->[0], |
88
|
|
|
|
|
|
|
'lat1' => $ra_bbox->[2], |
89
|
|
|
|
|
|
|
'lon2' => $ra_bbox->[1], |
90
|
|
|
|
|
|
|
'lat2' => $ra_bbox->[3], |
91
|
|
|
|
|
|
|
}); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
my $tmp = { |
94
|
|
|
|
|
|
|
address => $raw_reply->{display_name}, |
95
|
|
|
|
|
|
|
country => $raw_reply->{address}{country}, |
96
|
|
|
|
|
|
|
longitude => $raw_reply->{lon}, |
97
|
|
|
|
|
|
|
latitude => $raw_reply->{lat}, |
98
|
|
|
|
|
|
|
precision => $precision, |
99
|
|
|
|
|
|
|
}; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$response->add_response( $tmp, $self->get_name() ); |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
my $http_response = $self->{GeoCoder}->response(); |
105
|
0
|
|
|
|
|
|
$response->set_response_code($http_response->code()); |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
return $response; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 get_name |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Returns the name of the geocoder type - used by Geo::Coder::Many |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
0
|
1
|
|
sub get_name { my $self = shift; return 'osm ' . $self->{GeoCoder}->VERSION; } |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
1; # End of Geo::Coder::Many::OSM |