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) »
  • Batch geocoding script for Google API
Pages: [1]

Author Topic: Batch geocoding script for Google API  (Read 1456 times)

Dennis Gray

  • Ask me questions
  • ****
  • Posts: 472
  • Karma: 1
  • CiviCRM version: Various. See post.
  • CMS version: Drupal, Wordpress and Joomla. See post.
  • MySQL version: TBA
  • PHP version: TBA
Batch geocoding script for Google API
May 20, 2012, 05:10:16 pm
Has anyone developed a script that will look up longitude and latitude using the Google API taking into account the daily limits and throttling. It would also have to be able to update the database in place.

JonGold

  • Ask me questions
  • ****
  • Posts: 638
  • Karma: 81
    • Palante Technology
  • CiviCRM version: 4.1 to the latest
  • CMS version: Drupal 6-7, Wordpress 4.0+
  • PHP version: PHP 5.3-5.5
Re: Batch geocoding script for Google API
May 21, 2012, 09:24:05 am
From your question, I'm not sure if you're aware that there's an existing batch geocoding update script.  With Civi 4.1, the code is in your filesystem here:
/civicrm/CRM/Utils/Address/BatchUpdate.php

I also see /civicrm/bin/deprecated/UpdateAddress.php, which I'm pretty sure is the pre-4.1 command-line script you can run.

However, the daily limits aren't respected, though according to this page, the existing batch geocoding script has a throttle:
http://wiki.civicrm.org/confluence/display/CRMDOC41/Managing+Scheduled+Jobs
The relevant code is here, so you might want to:
* Change the "usleep" time - currently it sleeps for 5 seconds between requests.
* Change the first line to:
if ( $processGeocode && $totalGeocoded < 2500)

So it will respect daily limits. Though of course we wouldn't hardcode the magic number of 2500 into the code, but rather set it by a variable :)

                   
if ( $processGeocode ) {
// loop through the address removing more information
// so we can get some geocode for a partial address
// i.e. city -> state -> country

$maxTries = 5; do {
  if ( $this->throttle ) {
    usleep( 50000 );
  }




Sign up to StackExchange and get free expert CiviCRM advice: https://civicrm.org/blogs/colemanw/get-exclusive-access-free-expert-help

Dennis Gray

  • Ask me questions
  • ****
  • Posts: 472
  • Karma: 1
  • CiviCRM version: Various. See post.
  • CMS version: Drupal, Wordpress and Joomla. See post.
  • MySQL version: TBA
  • PHP version: TBA
Re: Batch geocoding script for Google API
May 21, 2012, 05:02:45 pm
This looks like what I am looking for. I haven't done much with the job scheduler except for CiviMail and missed this.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Discussion (deprecated) »
  • Feature Requests and Suggestions (Moderator: Dave Greenberg) »
  • Batch geocoding script for Google API

This forum was archived on 2017-11-26.