From: Faith Greenwood on
I am trying to do some geocoding w/ geo::coder::google. It works fine
but my problem is accessing the values in the hash. How can I return
the coordinates (ie '-122.397323','37.778993',)?

#here is the hash (as posted on CSPAN page for Geo::Coder::Google)
##Link for a more legible version:
http://search.cpan.org/~miyagawa/Geo-Coder-Google-0.06/lib/Geo/Coder/Google.pm
{
'AddressDetails' => {
'Country' => {
'AdministrativeArea' => {
'SubAdministrativeArea' => {
'SubAdministrativeAreaName' => 'San Francisco',
'Locality' => {
'PostalCode' => {
'PostalCodeNumber' => '94107'
},
'LocalityName' => 'San Francisco',
'Thoroughfare' => {
'ThoroughfareName' => '548 4th St'
}
}
},
'AdministrativeAreaName' => 'CA'
},
'CountryNameCode' => 'US'
}
},
'address' => '548 4th St, San Francisco, CA 94107, USA',
'Point' => {
'coordinates' => [
'-122.397323',
'37.778993',
0
]
}
}


------------
my code is as follows:

...
my $geocoder = Geo::Coder::Google->new(apikey=>'my_key');
my $location=undef; $location=$geocoder->geocode(location=>"548 4th
St, San Francisco, CA 94107, USA");

while (my ($key,$value)=each(%$location)){
print "$key=>$value\n";
}
...

#unfortunately, I am unable to get past this part and can't find
anything w/in the module to help.

thx!
From: Peter J. Holzer on
On 2010-02-15 07:17, Faith Greenwood <fgnowfg(a)gmail.com> wrote:
> I am trying to do some geocoding w/ geo::coder::google. It works fine
> but my problem is accessing the values in the hash. How can I return
> the coordinates (ie '-122.397323','37.778993',)?
>
> #here is the hash (as posted on CSPAN page for Geo::Coder::Google)
> ##Link for a more legible version:
> http://search.cpan.org/~miyagawa/Geo-Coder-Google-0.06/lib/Geo/Coder/Google.pm
> {
> 'AddressDetails' => {
[...]
> },
> 'address' => '548 4th St, San Francisco, CA 94107, USA',
> 'Point' => {
> 'coordinates' => [
> '-122.397323',
> '37.778993',
> 0
> ]
> }
> }
>
>
> ------------
> my code is as follows:
>
> ..
> my $geocoder = Geo::Coder::Google->new(apikey=>'my_key');
> my $location=undef; $location=$geocoder->geocode(location=>"548 4th
> St, San Francisco, CA 94107, USA");
>
> while (my ($key,$value)=each(%$location)){
> print "$key=>$value\n";
> }
> ..

Read perldoc perlreftut for an introduction to references.

If $location contains the hashref above, then

$location->{Point} is

{
'coordinates' => [
'-122.397323',
'37.778993',
0
]
}

$location->{Point}{coordinates} is

[
'-122.397323',
'37.778993',
0
]

and finally, $location->{Point}{coordinates}[0] is

'-122.397323',

hp