【发布时间】:2013-03-31 15:33:18
【问题描述】:
这是来自另一张海报。 (jpgunter)https://stackoverflow.com/users/1857927/jpgunter
use strict;
use LWP::Simple; # from CPAN
use JSON qw( decode_json ); # from CPAN
sub getLatLong($){
my ($address) = @_;
my $format = "json"; #can also to 'xml'
my $geocodeapi = "https://maps.googleapis.com/maps/api/geocode/";
my $url = $geocodeapi . $format . "?sensor=false&address=" . $address;
my $json = get($url);
my $d_json = decode_json( $json );
my $lat = $d_json->{results}->[0]->{geometry}->{location}->{lat};
my $lng = $d_json->{results}->[0]->{geometry}->{location}->{lng};
return ($lat, $lng);
}
它看起来正在做我想做的事,但是......有人能解释我把运行它的地址放在哪里以及输出到哪里吗?
我必须从另一个文件中遍历大约 5000 个城市,以完成我正在从事的“非学术”项目,显然手动操作的想法是可怕的。在过去的 7 年里,我也只做了很少的 perl,所以绝对任何帮助都会很棒。 我已经安装了 LWP 6.04 和 JSON 2.53。 如果我可以使用输入文件,请将其旋转(带有显示它的邮政编码)。 该行将在... "formatted_address" : "Geelong West VIC 3218, Australia", 只是不确定如何获得 3218。
原帖在这里... Get the Latitude and Longitude of an address using perl and Google's Geocode API
【问题讨论】:
-
查看服务条款;我的回忆是该 api 仅用于显示谷歌地图。无论如何,如果你做了 5000 次请求,你很可能在完成之前就被谷歌屏蔽了。
-
谢谢,这实际上非常有用,因为我还没有意识到这一点.. 查询仍然是相关的,因为我希望能够执行上述操作。
标签: perl geolocation latitude-longitude postal-code