You are here

function gmap_set_location in GMap Module 7

Same name and namespace in other branches
  1. 5 gmap.module \gmap_set_location()
  2. 6.2 gmap.module \gmap_set_location()
  3. 6 gmap.module \gmap_set_location()
  4. 7.2 gmap.module \gmap_set_location()

Location chooser utility function.

Creates a map that can be interactively used to fill a form with a location (latitude, longitude and zoom level).

Note: This is a utility function designed for location.module, there is no guarantee it will not be removed eventually.

Parameters

$map: Either a macro to use as the base map for setting a location, or an already set map associative array.

$form: A formset associative array. Cannot be more than one deep.

$fields: An associative array for the field names. 'latitude', 'longitude'=>name of respective array, 'address' is optional.

Return value

A string with the google map code to be inserted onto the page.

File

./gmap.module, line 420
GMap -- Routines to use the Google Maps API in Drupal.

Code

function gmap_set_location($map, &$form, $fields) {
  static $ctr = 0;
  $ctr++;
  if (!is_array($map)) {
    $map = array_merge(gmap_defaults(), gmap_parse_macro($map));
  }
  $id = 'loc' . $ctr;
  $map['id'] = $id;

  // This is a locpick map.
  $map['behavior']['locpick'] = TRUE;
  $element = array(
    '#type' => 'gmap',
    '#map' => $map['id'],
    '#gmap_settings' => $map,
  );
  $form[$fields['latitude']]['#map'] = $id;
  gmap_widget_setup($form[$fields['latitude']], 'locpick_latitude');
  $form[$fields['longitude']]['#map'] = $id;
  gmap_widget_setup($form[$fields['longitude']], 'locpick_longitude');
  if (isset($fields['address'])) {
    $form[$fields['address']]['#map'] = $id;
    gmap_widget_setup($form[$fields['address']], 'locpick_address');
  }
  return drupal_render($element);
}