The location module allows you to associate a geographic location with nodes (using the included Node Locations sub-module or the included Location CCK module), users (using the included User Locations sub-module) and taxonomy terms (using the included Location Taxonomy module).

Locations can consist of the following fields:

  1. Location name
  2. Street location (sometimes referred to as street 1)
  3. Additional (sometimes referred to as street 2)
  4. City
  5. State/Province
  6. Postal code (sometimes referred to as zip code)
  7. Country
  8. Coordinate chooser - This consists of Latitude and Longitude fields. If you are also using the gmap module users can enter these coordinates by clicking on a map.
  9. Phone number (provided by the included Location Phone sub-module)
  10. Fax number (provided by the included Location Fax sub-module)

There is also views support, which adds the ability to use location data as fields, arguments, filters and sorts and there is search integration for searching for content via location information (provided by the included Location Search sub-module).

Views and location search are also capable of doing proximity searches based on postal code (this requires some extra installation steps).

Using the gmap module along side the location module also allows you to show view results as markers on a google map.

Comments

karimahmed’s picture

Hope this helps someone.

Problem: I needed to create a new node/location in the callback function of a Views Bulk Operation (VBO). The view has provided the callback function a list of contractor node IDs within a given radius of an entered postcode (in $objects). and now we need to create a new enquiry node pre-populated with the list of contractors and the postcode entered in the view filter (form $context).

The user must then be presented with an edit form to complete the rest of the fields.

Solution:

/**
* Implementation of a Drupal action.
* Create a new enquiry node and populate the passed contractors in the contractors CCK field.
* Create a new location attached to the node, prepopulated with the postcode from the view
* Redirect user to enquiry edit form to manually complete the details
* @param $objects array of selected contractor node IDs
* @param $context array of other parameters (parameters from the view are in here)
*/
function contractor_enquiry(
  $objects,
  $context = array()
) {
  global $user;
  
  module_load_include('inc', 'node', 'node.pages');
  $node = array();
  $node['type'] = 'enquiry';
  $node['name'] = $user->name;		// node created by
  /*
   * populate contractor list from the contractor node_id list in $objects
   */
  foreach ( $objects as $key => $nid ){
  	$node['field_contractor'][$key]['nid']= $nid;
  }
  $node = (object) $node;		// cast to object
  $node = node_submit($node);	// prepare node for save and allow module hooks
  node_save($node);
  
  $view = (array) $context['view'];
  /*
   * Create a location already populated with the postcode from the view filter.
   */
  $locations = array();
  $locations[0]['postal_code'] = $view['exposed_input']['distance']['postal_code'];
  
  $criteria = array();
  $criteria['nid'] = $node->nid;
  $criteria['vid'] = $node->nid;
  $criteria['genid'] = 'contractor_enquiry';
  
  location_save_locations( $locations, $criteria );
  drupal_goto( 'node/'. $node->nid . '/edit' );
}
flamingvan’s picture

... at the end I think you might have meant:

$criteria['vid'] = $node->vid;

Anyway, that's what worked for me.