| Paste number 66219: | Here, have some zips for free |
| Pasted by: | atheos |
| When: | 10 months, 3 hours ago |
| Share: | Tweet this! | http://paste.lisp.org/+1F3F |
| Channel: | #openils-evergreen |
| Paste contents: |
#!/usr/bin/perl
use Geo::Coder::Google;
# Niles Ingalls
# Define the settings below, to brute force a list of addresses based on zip.
# note: google api does not return county. To view what the google API gives you,
# do a use Data::Dumper; print Dumpter($location)
# Indiana zip range is 46001 - 47997
# Georgia zip range is 30001 - 31999
# Michigan zip range is 48001 - 49971
# Google maps API can deal with Canadian postal
# codes the same way, but their codes are alphanumeric.
# someone else can extend that functionality to this script.
my $zip_low = '30001';
my $zip_high = '31999';
my $country_code = 'US';
my $apikey = 'getyourownapikey';
for ($zip = $zip_low;$zip < ($zip_high + 1);$zip++) {
my $geocoder = Geo::Coder::Google->new(apikey => $apikey);
my $location = $geocoder->geocode( location => $zip );
my $state = $location->{AddressDetails}->{Country}->{AdministrativeArea}->{AdministrativeAreaName};
my $city = $location->{AddressDetails}->{Country}->{AdministrativeArea}->{Locality}->{LocalityName};
my $country = $location->{AddressDetails}->{Country}->{CountryNameCode};
if ($country eq $country_code || $city > '') { print "|$state|$city|$zip||||\n"; }
}This paste has no annotations.