+=item country_full
+
+Returns the full country name.
+
+=cut
+
+sub country_full {
+ my $self = shift;
+ $self->code2country($self->get('country'));
+}
+
+sub code2country {
+ my( $self, $country ) = @_;
+
+ #a hash? not expecting an explosion of business from unrecognized countries..
+ return 'KKTC' if $country eq 'XC';
+
+ Locale::Country::code2country($country);
+}
+
+=item set_coord
+
+Look up the coordinates of the location using (currently) the Google Maps
+API and set the 'latitude' and 'longitude' fields accordingly.
+
+=cut
+
+sub set_coord {
+ my $self = shift;
+
+ #my $module = FS::Conf->new->config('geocode_module') || 'Geo::Coder::Googlev3';
+
+ my $geocoder = Geo::Coder::Googlev3->new;
+
+ my $location = eval {
+ $geocoder->geocode( location =>
+ $self->get('address1'). ','.
+ ( $self->get('address2') ? $self->get('address2').',' : '' ).
+ $self->get('city'). ','.
+ $self->get('state'). ','.
+ $self->country_full
+ );
+ };
+ if ( $@ ) {
+ warn "geocoding error: $@\n";
+ return;
+ }
+
+ my $geo_loc = $location->{'geometry'}{'location'} or return;
+ if ( $geo_loc->{'lat'} && $geo_loc->{'lng'} ) {
+ $self->set('latitude', $geo_loc->{'lat'} );
+ $self->set('longitude', $geo_loc->{'lng'} );
+ $self->set('coord_auto', 'Y');
+ }
+
+}
+