Skip to main content

Location, gmap, and gmap_location module interactions

If you want nodes to appear on a google map provided by the gmap_location module, you need to set up your system correctly.

from gmap_location function gmap_location_node_page() :

  $result=db_query("SELECT oid, longitude, latitude FROM {location} WHERE (longitude!=0 OR latitude !=0) AND type='node'");

So, the only nodes that will appear in a gmap_location-provided map are those where the type is 'node' and the longitude or latitude are non-zero in the location table. Ok, how do we get a lat/long value in that table?

Two ways:

One, the user has the "submit latitude/longitude" access permission, and enters lat/long info directly.

- OR -

If a user submits a node location with a zipcode, AND the user has the "submit latitude/longitude" access permission, then, and ONLY then, the location module will lookup the latitude / longitude from an internal zipcode table, and insert the found values into the location table.

To restate the rules:

  1. User must have "submit latitude/longitude" access permission
  2. Submitted content must have either lat/long info OR a valid zipcode

Next, I'll look into ways to update the location table automatically when there is a zipcode and no lat/long values provided, during a cron run. This will allow you to remove the "submit latitude/longitude" access permission from normal users, and still have contributed content with valid zipcode data show up in a google map.

You can get a list of candidate nodes using this SQL query:

SELECT * FROM {location} WHERE source = 0 AND postal_code <> '';

So, the (incomplete) Drupal PHP pseudocode process for updating the location table is:

$result=db_query('SELECT * FROM {location} WHERE souce = 0 AND postal_code <> '';");
while ($loc=db_fetch_object($result)) {
  $pcd = location_get_postalcode_data($loc); // from location.inc
  _update_loc_data_with_lat_long($loc, $pcd);
  _location_save(...); // from location.module
}

Note: These observations were made using location.module v 1.69 2006/09/08 20:00:25 and gmap_location.module v 1.20 (dated 10/25/2006)