line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Coder::YahooJapan::Inverse; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30843
|
use 5.008004; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
37
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1235
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
128778
|
|
|
1
|
|
|
|
|
47
|
|
8
|
1
|
|
|
1
|
|
3865
|
use HTTP::Request; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
108
|
|
9
|
1
|
|
|
1
|
|
3453
|
use Location::GeoTool; |
|
1
|
|
|
|
|
40596
|
|
|
1
|
|
|
|
|
6
|
|
10
|
1
|
|
|
1
|
|
559
|
use XML::Simple; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use utf8; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require Exporter; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
18
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
19
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# This allows declaration use Geo::Coder::YahooJapan::Inverse ':all'; |
22
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
23
|
|
|
|
|
|
|
# will save memory. |
24
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
) ] ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our @EXPORT = qw( |
31
|
|
|
|
|
|
|
invlookup |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Preloaded methods go here. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $entry_point = 'http://map.yahoo.co.jp/geo/lonlat2address'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $ua = undef; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub invlookup { |
43
|
|
|
|
|
|
|
my ($lat,$long,$opts) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
($lat && $long) or return undef; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$ua or $ua = LWP::UserAgent->new(agent => __PACKAGE__ . "/$VERSION"); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $datum = $opts->{datum} || 'wgs84'; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
die "Format of coordinate is wrong" if (($lat !~ /^[\-\+]?\d{1,2}(\.\d*)?$/) && ($long !~ /^[\-\+]?\d{1,2}(\.\d*)?$/)); |
52
|
|
|
|
|
|
|
die "Datum is wrong" if (($datum ne 'wgs84') && ($datum ne 'tokyo')); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $loc = eval { Location::GeoTool->create_coord($lat, $long, $datum, 'degree')}; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
($lat,$long) = $loc->datum_tokyo->format_mapion->array; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $req = HTTP::Request->new('POST',$entry_point); |
59
|
|
|
|
|
|
|
$req->content("$lat,$long"); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $res = $ua->request( $req ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$res or return undef; |
64
|
|
|
|
|
|
|
my $cont = $res->content; |
65
|
|
|
|
|
|
|
die "API error occured: maybe specified coordinate is out of Japan area" if ($cont =~ /
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $result = XMLin($cont)->{'gxml:spatialLocator'}; |
68
|
|
|
|
|
|
|
utf8::decode($result->{'gxml:AddressString'}->{'gxml:unstructuredAddressString'}); |
69
|
|
|
|
|
|
|
my @aditem = map { utf8::decode($_->{'content'}); $_->{'content'} } |
70
|
|
|
|
|
|
|
sort { $a->{'level'} <=> $b->{'level'} } |
71
|
|
|
|
|
|
|
@{$result->{'gxml:AddressString'}->{'gxml:AddressItem'}}; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return { |
74
|
|
|
|
|
|
|
address => $result->{'gxml:AddressString'}->{'gxml:unstructuredAddressString'}, |
75
|
|
|
|
|
|
|
addressitem => \@aditem, |
76
|
|
|
|
|
|
|
code => $result->{'GovernmentCode'}, |
77
|
|
|
|
|
|
|
}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
__END__ |