function gmap_set_location in GMap Module 7.2
Same name and namespace in other branches
- 5 gmap.module \gmap_set_location()
- 6.2 gmap.module \gmap_set_location()
- 6 gmap.module \gmap_set_location()
- 7 gmap.module \gmap_set_location()
Location chooser utility function.
@todo move this to GmapLocation or GmapContrib class.
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
mixed $map: Either a macro to use as the base map for setting a location, or an already set map associative array.
array $form: A formset associative array. Cannot be more than one deep.
array $fields: An associative array for the field names. 'latitude', 'longitude'=>name of respective array, 'address' is optional.
Return value
mixed A string with the google map code to be inserted onto the page.
File
- ./
gmap.module, line 324 - 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);
}