julietsstars
Technical User
Hope someone is familiar with this.
Server: Apache
Database: Postgre SQL
Issue with zips. In my postgresql I had two tables one titled "zips" and the other "zips_backup". "zips" became corrupt so I changed the perl script to pull from "zips_backup". The locator works great when searching by zip code but doesnt work if you search by city state.
Below is code
____________________________________________________________
Server: Apache
Database: Postgre SQL
Issue with zips. In my postgresql I had two tables one titled "zips" and the other "zips_backup". "zips" became corrupt so I changed the perl script to pull from "zips_backup". The locator works great when searching by zip code but doesnt work if you search by city state.
Below is code
____________________________________________________________
Code:
package WeilMclainDB::Zips;
use base qw/DBIx::Class/;
__PACKAGE__->load_components(qw/PK::Auto Core/);
__PACKAGE__->table('zips_backup');
__PACKAGE__->add_columns(qw/zip_code zip_type city_name city_type state_name state_abbr area_code latitude longitude/);
__PACKAGE__->resultset_class('WeilMclainDB::ZipsResultSet');
1;
package WeilMclainDB::ZipsResultSet;
use base 'DBIx::Class::ResultSet';
use Geo::Distance;
sub get_zip {
my ($self, $city, $state) = @_;
#return undef unless ($city && $state =~ /^(\d*)$/);
if (my $zip = $self->single({city_name => uc($city),state_abbr=>uc($state)},{columns => [qw/zip_code/]})) {
return $zip->get_column('zip_code');
}
return undef;
return $self->single({city_name=>uc($city),state_abbr=>uc($state)},{columns=>[qw/zip_code/]})->get_column('zip_code');
}
sub get_closest {
my ($self, $zip_code, $miles) = @_;
# First get the latitude and longititude for the given zip code
if (my $zip = $self->single({zip_code => $zip_code})) {
my $geo = Geo::Distance->new;
my $locations = $geo->closest(
dbh => $self->result_source->storage->dbh,
table => 'zips_backup',
lon => $zip->longitude,
lat => $zip->latitude,
unit => 'mile',
distance => $miles,
lon_field => 'longitude',
lat_field => 'latitude',
'sort' => 1,
fields => [qw/zip_code/],
);
my @zips_backup;
foreach my $result (@{$locations}) {
push (@zips_backup, $result->{zip_code});
}
return \@zips_backup;
}
else {
return undef;
}
}
1;