-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogleGeoCode_sample.pl
More file actions
43 lines (41 loc) · 1.09 KB
/
Copy pathgoogleGeoCode_sample.pl
File metadata and controls
43 lines (41 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -w
#
# Usage:
# echo 1428 Whisperwood Dr., Columbus GA. | perl googleGeoCode_sample.pl
#
use strict;
use warnings;
use LWP::UserAgent;
use LWP::Authen::Ntlm;
use Authen::NTLM;
ntlmv2(1);
ntlm_host('WORKSTATION');
use URI::Escape;
use Encode 'decode';
use Encode 'encode';
use JSON;
my $user = 'DOMAIN\USER';
my $pass = 'PASSWORD';
my $http_proxy = 'connect://PROXY.SERVER.FQDN:PORT';
my $appid = "APPID";
my $ua = LWP::UserAgent->new(ssl_opts => {verify_hostname => 0},
keep_alive => 1);
$ua->proxy([qw(http https)], $http_proxy);
$ua->credentials('PROXY.SERVER.FQDN:PORT', '', $user, $pass);
while (<>) {
chomp;
my @r = geocode({key => $_, appid => $appid});
print join("\t", @r, $_)."\n";
}
sub geocode {
my ($args_ref) = @_;
my $ek = URI::Escape::uri_escape($args_ref->{key});
my $murl =
"https://maps.googleapis.com/maps/api/geocode/json"
."?address=$ek&key=$args_ref->{appid}";
print $murl;
my $r = $ua->get($murl)->content;
print $r;
my $data = decode_json($r);
return (encode('UTF-8',$data->{result}{address})||"");
}