line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Fix::reverse_geocode; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1046
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
4
|
1
|
|
|
1
|
|
146
|
use Geo::Coder::Google; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
4
|
use Moo; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
283
|
use Catmandu::Fix::Has; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has path => (fix_arg => 1); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Fix::SimpleGetValue'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub emit_value { |
13
|
0
|
|
|
0
|
0
|
|
my ($self, $var) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
"if (is_string(${var})) {" . |
16
|
|
|
|
|
|
|
"${var} = Geo::Coder::Google->new(apiver => 3)->reverse_geocode(latlng => ${var}) // {};" . |
17
|
|
|
|
|
|
|
"}"; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 NAME |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Catmandu::Fix::reverse_geocode - Provide access to the Google geocoding API |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Lookup the location of |
27
|
|
|
|
|
|
|
# latlng: '34.1015473,-118.3387288' |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
reverse_geocode(latlng) |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# address: |
32
|
|
|
|
|
|
|
# address_components: |
33
|
|
|
|
|
|
|
# - long_name: Highland Avenue |
34
|
|
|
|
|
|
|
# short_name: Highland Ave |
35
|
|
|
|
|
|
|
# types: |
36
|
|
|
|
|
|
|
# - route |
37
|
|
|
|
|
|
|
# - long_name: Central LA |
38
|
|
|
|
|
|
|
# short_name: Central LA |
39
|
|
|
|
|
|
|
# types: |
40
|
|
|
|
|
|
|
# - neighborhood |
41
|
|
|
|
|
|
|
# - political |
42
|
|
|
|
|
|
|
# - long_name: Hollywood |
43
|
|
|
|
|
|
|
# short_name: Hollywood |
44
|
|
|
|
|
|
|
# types: |
45
|
|
|
|
|
|
|
# - sublocality_level_1 |
46
|
|
|
|
|
|
|
# - sublocality |
47
|
|
|
|
|
|
|
# - political |
48
|
|
|
|
|
|
|
# - long_name: Los Angeles |
49
|
|
|
|
|
|
|
# short_name: LA |
50
|
|
|
|
|
|
|
# types: |
51
|
|
|
|
|
|
|
# - locality |
52
|
|
|
|
|
|
|
# - political |
53
|
|
|
|
|
|
|
# - long_name: Los Angeles County |
54
|
|
|
|
|
|
|
# short_name: Los Angeles County |
55
|
|
|
|
|
|
|
# types: |
56
|
|
|
|
|
|
|
# - administrative_area_level_2 |
57
|
|
|
|
|
|
|
# - political |
58
|
|
|
|
|
|
|
# - long_name: California |
59
|
|
|
|
|
|
|
# short_name: CA |
60
|
|
|
|
|
|
|
# types: |
61
|
|
|
|
|
|
|
# - administrative_area_level_1 |
62
|
|
|
|
|
|
|
# - political |
63
|
|
|
|
|
|
|
# - long_name: United States |
64
|
|
|
|
|
|
|
# short_name: US |
65
|
|
|
|
|
|
|
# types: |
66
|
|
|
|
|
|
|
# - country |
67
|
|
|
|
|
|
|
# - political |
68
|
|
|
|
|
|
|
# - long_name: '90028' |
69
|
|
|
|
|
|
|
# short_name: '90028' |
70
|
|
|
|
|
|
|
# types: |
71
|
|
|
|
|
|
|
# - postal_code |
72
|
|
|
|
|
|
|
# formatted_address: Highland Avenue & Hollywood Boulevard, Los Angeles, CA 90028, USA |
73
|
|
|
|
|
|
|
# geometry: |
74
|
|
|
|
|
|
|
# location: |
75
|
|
|
|
|
|
|
# lat: 34.1015473 |
76
|
|
|
|
|
|
|
# lng: -118.3387288 |
77
|
|
|
|
|
|
|
# location_type: APPROXIMATE |
78
|
|
|
|
|
|
|
# viewport: |
79
|
|
|
|
|
|
|
# northeast: |
80
|
|
|
|
|
|
|
# lat: 34.1028962802915 |
81
|
|
|
|
|
|
|
# lng: -118.337379819709 |
82
|
|
|
|
|
|
|
# southwest: |
83
|
|
|
|
|
|
|
# lat: 34.1001983197085 |
84
|
|
|
|
|
|
|
# lng: -118.340077780291 |
85
|
|
|
|
|
|
|
# partial_match: !!perl/scalar:JSON::PP::Boolean 1 |
86
|
|
|
|
|
|
|
# place_id: EkFIaWdobGFuZCBBdmVudWUgJiBIb2xseXdvb2QgQm91bGV2YXJkLCBMb3MgQW5nZWxlcywgQ0EgOTAwMjgsIFVTQQ |
87
|
|
|
|
|
|
|
# types: |
88
|
|
|
|
|
|
|
# - intersection |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This code requires you to create a Google MAP API key: |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
https://console.developers.google.com//flows/enableapi?apiid=geocoding_backend&keyType=SERVER_SIDE |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Your UNIX environment should contain two variabels: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
export GMAP_CLIENT=<your_google_address> |
99
|
|
|
|
|
|
|
export GMAP_KEY=<your_api_key> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
As a free service a maximum of 5 requests per second are permitted, 2500 requests per day. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SEE ALSO |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L<Catmandu::Fix> , L<Geo::Coder::Google> |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |