Geo :: Google seems dead, fails tests, now what?

I tried installing Geo :: Google using CPAN ( http://metacpan.org/pod/Geo::Google v0.05) and it failed almost all the tests. I checked here http://matrix.cpantesters.org/?dist=Geo-Google+0.05 and confirms that this module fails to execute everything .

This seems to be an abandoned module, but I need to calculate the distance between two addresses from my Perl program . Any tips?

+4
source share
1 answer

I am trying to recover an unfinished module (Zoidberg), and the best thing you can do is to slip the results of CPANtesters to understand what went wrong to try to fix it.

This says google maps have a public api and even one with a simple web interface . I will try to make fun of you with an example, but to get started, try to execute some queries using LWP::UserAgent or WWW::Mechanize , and then analyze the results to find the answer.

Edit: Ok, here is an example. Toward the end, $data is a hash function of the data contained in the JSON response described in the link above. I also calculated the total distance for the (first) route.

 #!/usr/bin/perl use strict; use warnings; use JSON; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); my $origin = "60607"; my $destination = "60067"; my $site = 'http://maps.googleapis.com/maps/api/directions/'; my $mode = 'json'; my $page = $site . $mode . '?origin="' . $origin . '"&destination="' . $destination . '"&sensor=false'; my $response = $ua->get( $page ); my $json = $response->content(); my $data = decode_json $json; my @legs = @{ $data->{'routes'}[0]{'legs'} }; my $distance_meters = 0; foreach my $leg (@legs) { $distance_meters += $leg->{'distance'}{'value'}; } my $distance_kilometers = $distance_meters / 1000; my $distance_miles = $distance_kilometers * 0.62137119; print $distance_miles . " Miles\n"; 

Edit: And now, since I was bored on a Sunday afternoon:

 perl -e 'use JSON;use LWP::Simple;($s,$e) =@ARGV ;$m+=$_->{distance}{value} for@ {(decode_json get qq<http://maps.googleapis.com/maps/api/directions/json?origin="$s"&destination="$e"&sensor=false>)->{routes}[0]{legs}};printf"%.2f Miles\n",$m*0.6213e-3' 60607 60067 

Edit: And now the port of one liner to the Mokholichnaya system:

 perl -Mojo -E '$m+=$_->{distance}{value} for@ {g("http://maps.googleapis.com/maps/api/directions/json",form=>{origin=>shift,destination=>shift,sensor=>"false"})->json("/routes/0/legs")};printf"%.2f Miles\n",$m*0.6213e-3' 60607 60067 
+10
source

Source: https://habr.com/ru/post/1342293/


All Articles