Skip Menu |

This queue is for tickets about the Geo-Google CPAN distribution.

Report information
The Basics
Id: 30038
Status: new
Priority: 0/
Queue: Geo-Google

People
Owner: Nobody in particular
Requestors: jik [...] kamens.brookline.ma.us
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.05
Fixed in: (no value)



Subject: answer+suggestion and \x escapes are handled incorrectly
If Google returns an answer for a location and at the same time returns alternative suggestions, the answer that it returned should be used, and the alternatives should be ignored. This can happen if one of the words in the address being searched has many fewer matches in Google's database than another, similar word. In the current code base, if an answer and alternatives are returned, the answer is incorrectly ignored. The current code base expects character escapes to start with \u, but in my experience, they start with \x. The attached patch fixes both of these problems.
Subject: Geo-Google-0.05-suggest.patch
--- Google.pm.orig 2007-06-25 21:45:25.000000000 -0400 +++ Google.pm 2007-10-16 13:20:22.000000000 -0400 @@ -245,26 +245,41 @@ if ( $pages[0] =~ /did\snot\smatch\sany\slocations/i ) { $self->error( "Google couldn't find any locations matching $address." ) and return undef; } - # See if Google was unable to resolve the address, but suggested other addresses - # To see this, run a query for 695 Charles E Young Dr S, Westwood, CA 90024 - elsif ( $pages[0] =~ m#Did you mean:#is ) { - # Extract the queries from all the http get queries for alterate addresses - # \u003cdiv class=\"ref\"\u003e\u003ca href=\"/maps?v=1\u0026amp;q=695+Charles+E+Young+Drive+East,+Los+Angeles,+Los+Angeles,+California+90024,+United+States\u0026amp;ie=UTF8\u0026amp;hl=en\u0026amp;oi=georefine\u0026amp;ct=clnk\u0026amp;cd=2\" onclick=\"return loadUrl(this.href)\"\u003e - # We need it to fit the LQ query 'http://maps.google.com/maps?output=js&v=1&q=%s' - my @queries = $pages[0] =~ m#\\u003cdiv class=\\"ref\\"\\u003e\\u003ca href=\\"/maps\?v=1\\u0026amp;q=(.+?)\\u0026amp;#gsi; - # clear the $pages array so we can fill it with the pages from the @urls - @pages = (); - foreach my $suggested_query (@queries) { - push( @pages, get( sprintf( LQ, $suggested_query ) ) ); - } - } - # Verify that we actually retrieved pages to parse - if ( scalar(@pages) > 0 ) { - foreach my $page (@pages) { + while (my $page = shift @pages) { # attempt to locate the JSON formatted data block - if ($page =~ m#loadVPage\((.+), "\w+"\);}//]]>#is) { $response_json = $json->jsonToObj($1); } + if ($page =~ m#loadVPage\((.+), "\w+"\);}//]]>#is) { + $response_json = $json->jsonToObj($1); + if (! $response_json) { + $self->error("Found the JSON data block but was unable to " . + "parse it.") and return undef; + } + if (! ($response_json->{"overlays"} && + $response_json->{"overlays"}->{"markers"})) { + # See if Google was unable to resolve the address, but + # suggested other addresses To see this, run a query for + # 695 Charles E Young Dr S, Westwood, CA 90024 + if ($page =~ m#Did you mean:#is) { + # Extract the queries from all the http get queries + # for alterate addresses + # \u003cdiv class=\"ref\"\u003e\u003ca href=\"/maps?v=1\u0026amp;q=695+Charles+E+Young+Drive+East,+Los+Angeles,+Los+Angeles,+California+90024,+United+States\u0026amp;ie=UTF8\u0026amp;hl=en\u0026amp;oi=georefine\u0026amp;ct=clnk\u0026amp;cd=2\" onclick=\"return loadUrl(this.href)\"\u003e + # We need it to fit the LQ query + # http://maps.google.com/maps?output=js&v=1&q=%s' + my @queries = $page =~ m#\\(?:u00|x)3cdiv class=\\"ref\\"\\(?:u00|x)3e\\(?:u00|x)3ca href=\\"/maps\?v=1\\(?:u00|x)26amp;q=(.+?)\\(?:u00|x)26amp;#gsi; + foreach my $suggested_query (@queries) { + push( @pages, get( sprintf( LQ, $suggested_query ) ) ); + } + next; + } + else { + $self->error("Found the JSON Data block and was able to " . + "parse it, but it had no location markers " . + "in it. Maybe Google changed their JSON " . + "data structure?") and return undef; + } + } + } else { - $self->error( "Unable to locate the JSON format data in google's response.") and return undef; + $self->error( "Unable to locate the JSON format data in google's response.") and return undef; } if ( scalar(@{$response_json->{"overlays"}->{"markers"}}) > 0 ) { foreach my $marker (@{$response_json->{"overlays"}->{"markers"}}) { @@ -272,15 +287,6 @@ push @result, $loc; } } - else { - $self->error("Found the JSON Data block and was able to parse it, but it had no location markers " - . "in it. Maybe Google changed their JSON data structure?.") and return undef; - } - } - } - else { - $self->error("Google couldn't resolve the address $address but suggested alternate addresses. " - . "I attempted to download them but failed.") and return undef; } return @result; }