hashes (geo::coder::google)

F

Faith Greenwood

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!
 
P

Peter J. Holzer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top