How to do mass geocoding/re-geocoding of node locations

Last updated on
30 April 2025

(To do: Update this to include other location types.)

If you have imported a whole bunch of nodes that have location information and no coordinates or if you have a large number of nodes that need re-geocoding or something there is a way to do a mass geocode for those nodes.

There is an option on the locations settings page (admin/settings/location) titled "Enable JIT geocoding". If you check this then any locations that are loaded will be geocoded on load, if they have their source set to LOCATION_LATLON_JIT_GEOCODING, which is equal to the number 4. You can set this by modifying the source field of the location table in the database.
The source will also be changed when it is geocoded so the same locations won't be repeatedly re-geocoded.

(To do: Create a how to for setting up geocoding and link to it here.)
The steps for mass geocoding are (this assumes geocoding settings are set up correctly already):

  1. Check the Enable JIT geocoding option on the locations settings page (admin/settings/location).
  2. Using the command line or phpmyadmin update the source field of the locations you want to geocode to the number 4. Some SQL examples of doing this are (assuming your site isn't using a table prefix. If so you need to modify these accordingly):
    • All locations: UPDATE location SET source = 4
    • Locations for a specific set of nodes (replace the numbers in this to the node ids you want to target. Also, you might want to use vid instead of nid if you are using revisions): UPDATE location SET source = 4 WHERE lid IN (SELECT lid FROM location_instance WHERE nid IN (1, 2, 3, 4, 23, 134, 156, 45, 7))
    • Locations for a specific node type (in this case page): UPDATE location SET source = 4 WHERE lid IN (SELECT li.lid FROM location_instance li INNER JOIN node n ON li.vid = n.vid WHERE n.type = 'page')
  3. You then need to load all the nodes that need geocoding. To do this you could do one of the following (there would also be other ways of doing it):
    • Just do nothing and each time one of the nodes is viewed by a user it will be geocoded.
    • Write a custom PHP script that does a node_load() on all the nodes you want geocoded.
    • Use the views bulk operations module by doing the following steps:
      1. Install the views bulk operations module.
      2. Edit the admin_content view that the module provides (admin/build/views/edit/admin_content), go to the options for the Bulk Operations style (click the little gear image to the right of it), and make sure that Save post (node_save_action) is one of the Selected operations.
      3. Visit the page that view is on (by default it is admin/content/node2).
      4. Filter the view to get the nodes you want to geocode
      5. Select all the rows (clicking the Select all # rows in this view. button if necessary).
      6. Select the Save post bulk operation and click Execute.

Additionally, there is a sandbox project posted by EvanDonovan which has demonstration code for how to recode node locations on cron: http://drupal.org/sandbox/evandonovan/1106378

Help improve this page

Page status: Not set

You can: