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 »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • How to Restrict the Google maps lookup so only the Post Code and Country is sent
Pages: [1]

Author Topic: How to Restrict the Google maps lookup so only the Post Code and Country is sent  (Read 2281 times)

gibsonoliver

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 2
    • Northbridge Digital
How to Restrict the Google maps lookup so only the Post Code and Country is sent
December 07, 2011, 07:43:42 am
Hi

I've been trying to work out how you can restrict the Google Maps lookup so only the Post Code / Country is sent.

The static function used is listed below but whatever changes I make it still seems to send all address fields.
Any help would be really appreciated, Oliver


    static function &getMapInfo( $ids, $locationTypeID = null )
    {
        $idString = ' ( ' . implode( ',', $ids ) . ' ) ';
        $sql = "
   SELECT civicrm_contact.id as contact_id,
          civicrm_contact.contact_type as contact_type,
          civicrm_contact.display_name as display_name,
          civicrm_address.street_address as street_address,
          civicrm_address.supplemental_address_1 as supplemental_address_1,
          civicrm_address.supplemental_address_2 as supplemental_address_2,
          civicrm_address.city as city,
          civicrm_address.postal_code as postal_code,
          civicrm_address.postal_code_suffix as postal_code_suffix,
          civicrm_address.geo_code_1 as latitude,
          civicrm_address.geo_code_2 as longitude,
          civicrm_state_province.abbreviation as state,
          civicrm_country.name as country,
          civicrm_location_type.name as location_type
     FROM civicrm_contact
LEFT JOIN civicrm_address ON civicrm_address.contact_id = civicrm_contact.id
LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id
LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
LEFT JOIN civicrm_location_type ON civicrm_location_type.id = civicrm_address.location_type_id
WHERE civicrm_address.geo_code_1 IS NOT NULL
AND civicrm_address.geo_code_2 IS NOT NULL
AND civicrm_contact.id IN $idString ";

        $params = array( );
        if (!$locationTypeID) {
            $sql .= " AND civicrm_address.is_primary = 1";
        } else {
            $sql .= " AND civicrm_address.location_type_id = %1";
            $params[1] = array( $locationTypeID, 'Integer' );
        }

        $dao =& CRM_Core_DAO::executeQuery( $sql, $params );

        $locations = array( );
        $config = CRM_Core_Config::singleton( );

        while ( $dao->fetch( ) ) {
            $location = array( );
            $location['contactID'   ] = $dao->contact_id;
            $location['displayName' ] = addslashes( $dao->display_name );
            $location['city'        ] = $dao->city;
            $location['state'       ] = $dao->state;
            $location['postal_code' ] = $dao->postal_code;
            $location['lat'         ] = $dao->latitude;
            $location['lng'         ] = $dao->longitude;
            $location['marker_class'] = $dao->contact_type;
            $address = '';
           
            CRM_Utils_String::append( $address, '<br />',
                                      array( $dao->street_address,
                                             $dao->supplemental_address_1,
                                             $dao->supplemental_address_2,
                                             $dao->city ) );
            CRM_Utils_String::append( $address, ', ',
                                      array(   $dao->state, $dao->postal_code ) );
            CRM_Utils_String::append( $address, '<br /> ',
                                      array( $dao->country ) );
            $location['address'       ] = addslashes( $address );
            $location['displayAddress'] = str_replace( '<br />', ', ', $address );
            $location['url'           ] = CRM_Utils_System::url( 'civicrm/contact/view', 'reset=1&cid=' . $dao->contact_id );
            $location['location_type' ] = $dao->location_type;
            require_once 'CRM/Contact/BAO/Contact/Utils.php';
            $location['image'] =
                CRM_Contact_BAO_Contact_Utils::getImage( isset( $dao->contact_sub_type ) ?
                                                         $dao->contact_sub_type : $dao->contact_type,false,$dao->contact_id );
            $locations[] = $location;
        }
        return $locations;
    }   
}
Oliver Gibson, Northbridge Digital

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: How to Restrict the Google maps lookup so only the Post Code and Country is sent
December 12, 2011, 11:00:23 pm
Hi gibsonoliver,
If I asked for quick fix, it can be following (just by modifying variable $address, which is used to show address for google map marker popup ).

But IMO we should have some admin setting in backend to setup address fields to be shown on map, like we can manage address fields for contact that should be visible on view/edit contact.
Code: [Select]
Index: CRM/Contact/BAO/Contact/Location.php
===================================================================
--- CRM/Contact/BAO/Contact/Location.php (revision 37708)
+++ CRM/Contact/BAO/Contact/Location.php (working copy)
@@ -177,6 +177,7 @@
             $location['marker_class'] = $dao->contact_type;
             $address = '';
             
+            /*
             CRM_Utils_String::append( $address, '<br />',
                                       array( $dao->street_address,
                                              $dao->supplemental_address_1,
@@ -186,6 +187,9 @@
                                       array(   $dao->state, $dao->postal_code ) );
             CRM_Utils_String::append( $address, '<br /> ',
                                       array( $dao->country ) );
+            */
+            CRM_Utils_String::append( $address, '<br />', array( $dao->country ) );
+            CRM_Utils_String::append( $address, ', ', array( $dao->postal_code ) );
             $location['address'       ] = addslashes( $address );
             $location['displayAddress'] = str_replace( '<br />', ', ', $address );
             $location['url'           ] = CRM_Utils_System::url( 'civicrm/contact/view', 'reset=1&cid=' . $dao->contact_id );


Rajan

gibsonoliver

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 2
    • Northbridge Digital
Re: How to Restrict the Google maps lookup so only the Post Code and Country is sent
December 13, 2011, 12:44:05 am
Hi Rajan

I tried the fix (and it is something I'd tried myself) but when you save a contact it still seems to send all the standard data to Google maps for geo coding. i.e. When I edit a contact and change the city this is picked up in the geo data.
Am I missing something? Have I got the correct function?

I'm not sure this should be built into the system admin as this is a specific case; the contacts are UK Churches who have very poor addresses and I know only the Post Code data is accurate.

Thanks for your help with this
Oliver
Oliver Gibson, Northbridge Digital

Rajan Mayekar

  • I post frequently
  • ***
  • Posts: 177
  • Karma: 20
    • Rajan's Blogs
Re: How to Restrict the Google maps lookup so only the Post Code and Country is sent
December 13, 2011, 01:57:45 am
Hi gibsonoliver,

No problem, I thought that you wanted to show country and postal address on marker popup of gmap :)

Ok, so what you want is to calculate Latitude and Longitude based on country and postal code from gmap api ( excluding all other address fields ).
For this you need to comment some code from file
CRM/Utils/Geocode/Geogle.php
in function format( &$values, $stateName = false )
comment the code which used to pass address related fields.

You can refer following diff:
Code: [Select]
Index: CRM/Utils/Geocode/Google.php
===================================================================
--- CRM/Utils/Geocode/Google.php (revision 37708)
+++ CRM/Utils/Geocode/Google.php (working copy)
@@ -81,6 +81,7 @@
         
         $add = '';
 
+        /*
         if (  CRM_Utils_Array::value( 'street_address', $values ) ) {
             $add  = urlencode( str_replace('', '+', $values['street_address']) );
             $add .= ',+';
@@ -109,7 +110,7 @@
                 $add .= ',+';
             }
         }
-       
+        */

I hope this will work for you :)
Let me know!

Rajan

gibsonoliver

  • I post occasionally
  • **
  • Posts: 65
  • Karma: 2
    • Northbridge Digital
Re: How to Restrict the Google maps lookup so only the Post Code and Country is sent
December 13, 2011, 02:36:28 am
Hi Rajan

That works perfectly!
Thank you for your help

Oliver
Oliver Gibson, Northbridge Digital

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • How to Restrict the Google maps lookup so only the Post Code and Country is sent

This forum was archived on 2017-11-26.