<$geocoder = Geo::Coder::Google->new(apiver => 3); eval { $latlong = $geocoder->geocode(location => $location); print Dumper($latlong); }; $map_coords = $latlong->{geometry}{location}{lat} . " +" . $latlong->{geometry}{location}{lng}; $country = $latlong->{address_components}{types}{count +ry}{long_name};
If the correct answer is 'South Africa' (address_components >> types >> country >> long_name), how do I grab that?$VAR1 = { 'formatted_address' => 'Johannesburg, South Africa', 'types' => [ 'locality', 'political' ], 'address_components' => [ { 'types' => [ 'locality', 'political' ], 'short_name' => 'Johannesburg', 'long_name' => 'Johannesburg' }, { 'types' => [ 'administrative_are +a_level_3', 'political' ], 'short_name' => 'Johannesburg', 'long_name' => 'Johannesburg' }, { 'types' => [ 'administrative_are +a_level_2', 'political' ], 'short_name' => 'City of Johanne +sburg Metropolitan Municipality', 'long_name' => 'City of Johannes +burg Metropolitan Municipality' }, { 'types' => [ 'administrative_are +a_level_1', 'political' ], 'short_name' => 'GP', 'long_name' => 'Gauteng' }, { 'types' => [ 'country', 'political' ], 'short_name' => 'ZA', 'long_name' => 'South Africa' } ], 'geometry' => { 'viewport' => { 'southwest' => { 'lat' => '- +26.2389231', 'lng' => '2 +7.942449' }, 'northeast' => { 'lat' => '- +26.1041199', 'lng' => '2 +8.1376001' } }, 'location' => { 'lat' => '-26.2041028', 'lng' => '28.0473051' }, 'location_type' => 'APPROXIMATE', 'bounds' => { 'southwest' => { 'lat' => '-26 +.2389231', 'lng' => '27. +942449' }, 'northeast' => { 'lat' => '-26 +.1041199', 'lng' => '28. +1376001' } } } }; Not a HASH reference at cvlt_jobs_2 line 239.
In reply to Parsing a JSON response by mcoblentz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |