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) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Batch Geocoding using Supplemental Address Fields
Pages: [1]

Author Topic: Batch Geocoding using Supplemental Address Fields  (Read 1346 times)

theitd

  • I’m new here
  • *
  • Posts: 22
  • Karma: 1
    • the ITD
  • CiviCRM version: 3.4.7
  • CMS version: 1.15.26
  • MySQL version: 5.1.66
  • PHP version: 5.3
Batch Geocoding using Supplemental Address Fields
February 16, 2009, 03:24:00 pm
Hi there,

I've been battling with geocoding for quite a while and have found an answer which I thought might help others in the same boat (usually in the middle of the South Pacific).

I am in no way a PHP developer, as you may be able to tell from the slightly 'ham-fisted' work-around - so I apologise in advance if the edits below seem inappropriate or poorly written. I'm running version 2.1.4 on Joomla 1.5.9 and have localised the settings to UK only. In an effort to keep things simple, I plumped for using the following address fields:

Street Address,
Supplemental Address Line 1,
Supplemental Address Line 2,
City,
State (County),
and Country.

Although this kept the requested sign-up fields to a minimum, it meant that none of the addresses successfully mapped (using Google or Yahoo). I found that the two Supplemental Addresses weren't sent to the Google Maps API, and when asked to find Honeysuckle Cottage near London, Google understandably returned a blank.

I therefore edited two files so that these fields could be used in the URI, and removed the Street Address (commonly the House Name) unless the other fields are empty. I found that the house name, more often that not, caused the request to fail.

The two files are:
<joomla_crm_root>/administrator/components/com_civicrm/civicrm/bin/UpdateAddress.php and
<joomla_crm_root>/administrator/components/com_civicrm/civicrm/CRM/Utils/Geocode/Google.php

In UpdateAddress.php, change:

Code: [Select]
$query = "
SELECT     c.id,
           a.id as address_id,
           a.street_address,
           a.city,
           a.postal_code,
           s.name as state,
           o.name as country
FROM       civicrm_contact  c

to:

Code: [Select]
$query = "
SELECT     c.id,
           a.id as address_id,
           a.street_address,
           a.city,
           a.postal_code,
           s.name as state,
           o.name as country,
          a.supplemental_address_1,
          a.supplemental_address_2,
          a.supplemental_address_3
FROM       civicrm_contact  c

and change:

Code: [Select]
$params = array( 'street_address'    => $dao->street_address,
                 'postal_code'       => $dao->postal_code,
                 'city'              => $dao->city,
                 'state_province'    => $dao->state,
                 'country'           => $dao->country );

to:

Code: [Select]
$params = array( 'street_address'    => $dao->street_address,
                 'postal_code'       => $dao->postal_code,
                'supplemental_address_1'        => $dao->supplemental_address_1,
                'supplemental_address_2'        => $dao->supplemental_address_2,
                'supplemental_address_3'        => $dao->supplemental_address_3,
                 'city'              => $dao->city,
                 'state_province'    => $dao->state,
                 'country'           => $dao->country );

In Google.php, change:

Code: [Select]
if (  CRM_Utils_Array::value( 'street_address', $values ) ) {
$add  = urlencode( str_replace('', '+', $values['street_address']) );
$add .= ',+';
}

to:

Code: [Select]
//        if (  CRM_Utils_Array::value( 'street_address', $values ) ) {
//            $add  = urlencode( str_replace('', '+', $values['street_address']) );
//            $add .= ',+';
//        }

$supplemental_address_1 = ( CRM_Utils_Array::value( 'supplemental_address_1', $values ) );
$supplemental_address_2 = ( CRM_Utils_Array::value( 'supplemental_address_2', $values ) );

if ((empty ( $supplemental_address_1 ) ) && (empty ( $supplemental_address_2 ) )) {
            $add  = urlencode( str_replace('', '+', $values['street_address']) );
            $add .= ',+';
}

if ( $supplemental_address_1 ) {
$add .= '+' .urlencode( str_replace('', '+', $values['supplemental_address_1']) );
$add .= ',+';
}

if (  $supplemental_address_2 ) {
$add .= '+' .urlencode( str_replace('', '+', $values['supplemental_address_2']) );
$add .= ',+';
}

The most reliable method for then retrieving the coordinates seemed to be using wget:

Code: [Select]
wget 'http://<joomla_crm_root>/administrator/components/com_civicrm/civicrm/bin/UpdateAddress.php?name=<your_super_user>&pass=<your_super_pass>&key=<your_predefined_site_key>start=1&end=1000'
I stopped short of saying 'if all else fails, just use the postal_code' - but it retrieved the vast majority of 500 addresses.
I know that the supplemental fields are exactly what they say on the tin, but from what I could understand of the original request, only the street address, city and state were used to determine the location.

Honeysuckle Cottage is no longer a hermit's retreat in the Pacific Ocean but can be found in a small hamlet just outside Guildford, Surrey, UK.

If I should stand corrected on either the method or the code, please feel free.
Otherwise, 'hope this helps.
Too err is human, to really foul things up needs a computer.

petednz

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4899
  • Karma: 193
    • Fuzion
  • CiviCRM version: 3.x - 4.x
  • CMS version: Drupal 6 and 7
Re: Batch Geocoding using Supplemental Address Fields
February 16, 2009, 10:07:06 pm
It's actually quite nice here in the South Pacific - honeysuckle and all ;D
Sign up to StackExchange and get free expert advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

pete davis : www.fuzion.co.nz : connect + campaign + communicate

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Batch Geocoding using Supplemental Address Fields

This forum was archived on 2017-11-26.