line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::Many::Google; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
62
|
|
4
|
2
|
|
|
2
|
|
28
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
58
|
|
5
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
135
|
|
6
|
2
|
|
|
2
|
|
1356
|
use Geo::Coder::Many::Util; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
118
|
|
7
|
2
|
|
|
2
|
|
13
|
use base 'Geo::Coder::Many::Generic'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
693
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Geo::Coder::Many::Google - Plugin for the google maps geocoder |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.02 |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Requires Geo::Coder::Google 0.06 or above |
22
|
0
|
|
|
0
|
|
|
sub _MIN_MODULE_VERSION { return '0.06'; } |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
This class wraps Geo::Coder::Google such that it can be used in |
28
|
|
|
|
|
|
|
Geo::Coder::Many, by converting the results to a standard form. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Note: Geo::Coder::Google uses the deprecated version 2 of the Google |
31
|
|
|
|
|
|
|
geocoder. There is a newer Geo::Coder::Googlev3 (also supported by |
32
|
|
|
|
|
|
|
Geo::Coder::Many). |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 geocode |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Takes a location string, geocodes it using Geo::Coder::Google, and returns the |
39
|
|
|
|
|
|
|
result in a form understandable to Geo::Coder::Many |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# see details of google's response format here: |
44
|
|
|
|
|
|
|
# v2: http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding |
45
|
|
|
|
|
|
|
# v3: http://code.google.com/apis/maps/documentation/geocoding/ |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub geocode { |
48
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my $location = shift; |
50
|
0
|
0
|
|
|
|
|
defined $location or croak "Geo::Coder::Many::Google::geocode |
51
|
|
|
|
|
|
|
method must be given a location."; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my @raw_replies = $self->{GeoCoder}->geocode( $location ); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my $Response = Geo::Coder::Many::Response->new( { location => $location } ); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
foreach my $raw_reply ( @raw_replies ) { |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $precision = 0; # unknown |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
0
|
|
|
|
if (defined($raw_reply->{ExtendedData}) |
62
|
|
|
|
|
|
|
&& defined($raw_reply->{ExtendedData}{LatLonBox}) ){ |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $box = $raw_reply->{ExtendedData}{LatLonBox}; |
65
|
|
|
|
|
|
|
# lng and lat in decimal degree format |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$precision = |
68
|
|
|
|
|
|
|
Geo::Coder::Many::Util::determine_precision_from_bbox({ |
69
|
|
|
|
|
|
|
'lon1' => $box->{south}, |
70
|
|
|
|
|
|
|
'lat1' => $box->{west}, |
71
|
|
|
|
|
|
|
'lon2' => $box->{north}, |
72
|
|
|
|
|
|
|
'lat2' => $box->{east}, |
73
|
|
|
|
|
|
|
}); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $tmp = { |
77
|
|
|
|
|
|
|
address => $raw_reply->{address}, |
78
|
|
|
|
|
|
|
country => $raw_reply->{AddressDetails}{Country}{CountryNameCode}, |
79
|
|
|
|
|
|
|
latitude => $raw_reply->{Point}{coordinates}[1], |
80
|
|
|
|
|
|
|
longitude => $raw_reply->{Point}{coordinates}[0], |
81
|
|
|
|
|
|
|
precision => $precision, |
82
|
|
|
|
|
|
|
}; |
83
|
0
|
|
|
|
|
|
$Response->add_response( $tmp, $self->get_name()); |
84
|
|
|
|
|
|
|
} |
85
|
0
|
|
|
|
|
|
return $Response; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 get_name |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
The short name by which Geo::Coder::Many can refer to this geocoder. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
0
|
1
|
|
sub get_name { my $self = shift; return 'google ' . $self->{GeoCoder}->VERSION; } |
|
0
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |