Hi,
I'm writing a perl script thats goal is to read a delimited file containing a 
userid and an address to google maps where the address is converted into 
latitude and longitude.  The problem I'm having is with the result I'm 
printing.  Each line is unique via the userid when its printed but I'm getting 
the same latitude and longitude for each address.  I think the problem is I 
need to wait x amount of seconds before i send each url to google, but I'm not 
really sure how to accomplish that.  To be truthful I'm not even sure that is 
the problem.  I've attached my script, input file, and result.  Note its 
personal data so I've had to anonymize the input file and the results.  


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/perl
use warnings; 
use strict; 
use LWP::Simple;

open (ADDRESSOUT, 'addressout.txt'); 

while (<ADDRESSOUT>) {     #the start of the loop
    chomp;         #dropping line characters
    my @addressfield = split(/\:\:\:/, $_); 
   
    my $geoaddress = $addressfield[1] =~ s/ /\+/;
    my $googlekey = "unique google map api key";
    my $geocode_csv = 
get("http://maps.google.com/maps/geo?q=$geoaddress&output=csv&sensor=false&key=$googlekey";)
    or die 'Unable to get page';
    my @geoarray = split(/,/, $geocode_csv);
    print "$addressfield[0],$geoarray[2],$geoarray[3]\n";
}  #end of the loop

close (ADDRESSOUT);  #closing the file
exit 0;

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
addressout.txt
32986000382444:::34 main street anytown, tn 39455
31686000146174:::76 second avenue anytown, tn 39455
31685000781354:::1 park lane anytown, tn 39455
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
result
32986000382444 ,49.3961500,32.7630300
31686000146174 ,49.3961500,32.7630300
31685000781354 ,49.3961500,32.7630300
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to