mcoblentz has asked for the wisdom of the Perl Monks concerning the following question:
<$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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing a JSON response
by Your Mother (Archbishop) on Jul 25, 2014 at 18:43 UTC | |
by mcoblentz (Scribe) on Jul 25, 2014 at 19:30 UTC | |
|
Re: Parsing a JSON response
by wjw (Priest) on Jul 25, 2014 at 18:19 UTC | |
by GrandFather (Saint) on Jul 25, 2014 at 19:55 UTC | |
by mcoblentz (Scribe) on Jul 25, 2014 at 18:24 UTC | |
by mcoblentz (Scribe) on Jul 25, 2014 at 22:20 UTC | |
by Anonymous Monk on Jul 25, 2014 at 23:42 UTC | |
by mcoblentz (Scribe) on Jul 27, 2014 at 00:44 UTC |