CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Address Standardization using yahoo & google
Pages: [1]

Author Topic: Address Standardization using yahoo & google  (Read 5112 times)

Blake

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 5
    • LinkedIn Profile
Address Standardization using yahoo & google
September 03, 2009, 09:17:12 am
In light of hit or miss performance of the USPS address standardization and its limited scope to the US, couldn't yahoo or google APIs be used for a similar functionality?

I easily modified the geocoding files and update script to insert 9 digit zip codes from yahoo and it works great (below), but it would be nice to have that full address standardization functionality built in. This might also be of more use to the non-US crowd.

From civicrm/CRM/Utils/Geocode/Yahoo.php
Code: [Select]
133            $values['geo_code_1'] = $ret['Latitude' ];
134            $values['geo_code_2'] = $ret['Longitude'];
              $values['postal_code'] = $ret['Zip'];
136            return true;

and from civicrm/bin/UpdateAddress.php
Code: [Select]
156            $address->geo_code_1 = $params['geo_code_1'];
157            $address->geo_code_2 = $params['geo_code_2'];
              $address->postal_code = $params['postal_code'];
158            $address->save( );

robinhood

  • I post frequently
  • ***
  • Posts: 153
  • Karma: 6
  • CiviCRM version: 4.5.5
  • CMS version: Drupal 7.34
  • MySQL version: 5.1.56
  • PHP version: 5.3.5
Re: Address Standardization using yahoo & google
September 06, 2009, 05:49:55 am
Agree that this would be a good addition especially for non-US addresses.  But what is hit or miss about the USPS address standardization?  Works perfectly here.

Blake

  • I post occasionally
  • **
  • Posts: 36
  • Karma: 5
    • LinkedIn Profile
Re: Address Standardization using yahoo & google
September 08, 2009, 09:37:44 am
Getting approval from USPS to use the service isn't automatic, as detailed by Paul Fisher in http://civicrm.org/node/627

TallDavid

  • I post occasionally
  • **
  • Posts: 41
  • Karma: 2
    • ATO Zeta Mu Alumni
  • CiviCRM version: 3.4.8
  • CMS version: Drupal 6.22
  • MySQL version: 5.1.52
  • PHP version: 5.2.13
Re: Address Standardization using yahoo & google
December 12, 2009, 05:51:43 pm
RobinHood, are you successfully using the USPS Address Standardization with the USPS Production (not the testing) server?  I've received USPS authorization to use the Production system, but, can't get CiviCRM to work on these transactions.  If you have been successful using the USPS Production server, what version of CiviCRM are you using?

noah

  • I’m new here
  • *
  • Posts: 18
  • Karma: 4
Re: Address Standardization using yahoo & google
January 31, 2010, 07:03:29 pm
Quote from: Blake on September 03, 2009, 09:17:12 am
I easily modified the geocoding files and update script to insert 9 digit zip codes from yahoo and it works great (below), but it would be nice to have that full address standardization functionality built in. This might also be of more use to the non-US crowd.

I made these modifications and they work fine (well, the first one works fine -- I haven't had occasion to test the second). I've been wanting this functionality for so long, it's great! Here's my slightly changed version, which tries to be polite to existing postal code data (even if the existing data is incorrect). It also splits the postal code into postal_code and postal_code_suffix:

Code: [Select]
133            $values['geo_code_1'] = $ret['Latitude' ];
134            $values['geo_code_2'] = $ret['Longitude'];
               $current_pc = CRM_Utils_Array::value( 'postal_code', $values );
               // if a postal code was already entered, don't change it, except to make it more precise
               if (!$current_pc or (strpos($ret['Zip'], $current_pc) === 0)) {
                 $values['postal_code'] = $ret['Zip'];
                 /* the following logic to split the string was borrowed from CRM/Core/BAO/Address.php
                     -- CRM_Core_BAO_Address::fixAddress. This is actually the function that calls the geocoding script
                     to begin with, but the zipcode business takes place before geocoding gets called.
                 */
                 if ( preg_match('/^(\d{4,5})[+-](\d{4})$/',
                           $ret['Zip'],
                           $match) ) {
                   $values['postal_code']        = $match[1];
                   $values['postal_code_suffix'] = $match[2];
                 }
               }
136            return true;

you could put a similar check in civicrm/bin/UpdateAddress.php, modifying Blake's code --
Code: [Select]
               if (!$dao->postal_code or (strpos($params['postal_code'], $dao->postal_code) === 0))and split the postal code similarly.
« Last Edit: January 31, 2010, 07:09:17 pm by noah »

noah

  • I’m new here
  • *
  • Posts: 18
  • Karma: 4
Re: Address Standardization using yahoo & google
January 11, 2011, 01:59:26 am
Here's a version for Google (CRM/Utils/Geocode/Google.php):

Code: [Select]
143             if ( $val[0] && $val[1] ) {
144                 $values['geo_code_1'] = $val[1];
145                 $values['geo_code_2'] = $val[0];
                    //ZIP CODE CODE BELOW ADDED BY NOAH MILLER
                    $zipobj = $xml->Response->Placemark->AddressDetails->Country->AdministrativeArea->SubAdministrativeArea->Locality->PostalCode->PostalCodeNumber;
                    $zip = (string)$zipobj;
                    $current_pc = CRM_Utils_Array::value( 'postal_code', $values );
                    // if a postal code was already entered, don't change it, except to make it more precise
                    if (!$current_pc or (strpos($zip, $current_pc) === 0)) {
                      $values['postal_code'] = $zip;
                      /* the following logic to split the string was borrowed from CRM/Core/BAO/Address.php
                          -- CRM_Core_BAO_Address::fixAddress. This is actually the function that calls the geocoding script
                          to begin with, but the zipcode business takes place before geocoding gets called.
                      */
                      if ( preg_match('/^(\d{4,5})[+-](\d{4})$/',
                                $zip['Zip'],
                                $match) ) {
                        $values['postal_code']        = $match[1];
                        $values['postal_code_suffix'] = $match[2];
                      }
                    }
146                 return true;
165             }

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Address Standardization using yahoo & google

This forum was archived on 2017-11-26.