payprop / html-googlemaps-v3

Fork of HTML::GoogleMaps to fix issues
2 stars 1 forks source link

Not a hash reference #17

Closed nigelhorne closed 6 years ago

nigelhorne commented 6 years ago

Any idea what could have caused this? I have a large amount of data and the error message doesn't tell me enough to work out which location is causing the error.

Not a HASH reference at /home/hornenj/perl5/lib/perl5/HTML/GoogleMaps/V3.pm line 108.

Here is line 108:

sub _text_to_point {
    my ( $self,$point_text ) = @_;

    # IE, already a long/lat pair
    return [ reverse @$point_text ] if ref( $point_text ) eq "ARRAY";

    if ( my @loc = $self->{geocoder}->geocode( location => $point_text ) ) {
        if ( my $location = $loc[0] ) {
            return [
                $location->{geometry}{location}{lat},    ###### line 108 is here
                $location->{geometry}{location}{lng},
            ];
        }
    }

    # Unknown
    return 0;
}
leejo commented 6 years ago

I would suggest sticking some debug in your local copy of the module to find out why $locaion is not a hash ref. Possibly add a check at line 106:

if ( ref( $location ) ne 'HASH' ) {
    warn "$point_text didn't return a HASH ref as first element from ->geocode";
    return 0;
}
nigelhorne commented 6 years ago

Thanks. I think something is broken in Geo::Coder::List when you do a more than one lookup on a location that doesn't exist.

nigelhorne commented 6 years ago

I think the warning is a good one, and vote it goes into the code.