You are here

function gmap_simple_map in GMap Module 7.2

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

Simple way to draw a map from inside a theme.

@todo move this to GmapDraw class

Parameters

array $latitude: Latitude of marker.

array $longitude: Longitude of marker.

string $markername: Marker to use.'' will fall back to google's default marker.

string $info: What to show in the bubble when the marker is clicked. Leave blank if you don't want a bubble.

string $zoom: 'default' will use the default zoom from the settings page. 3 is usually a good value to use.

string $width: 'default' will use the default width from the settings page.

string $height: 'default' will use the default height from the settings page.

bool $autoshow: If set to TRUE, automatically show the marker bubble.

array $map: Override parts of the map array. If you need to do much with this, you should probabaly be putting together the map array manually.

Return value

string Return rendered element.

File

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

Code

function gmap_simple_map($latitude, $longitude, $markername = '', $info = '', $zoom = 'auto', $width = 'default', $height = 'default', $autoshow = FALSE, $map = array()) {
  $settings = array(
    'id' => gmap_get_auto_mapid(),
    // Center the map on the marker.
    'latitude' => $latitude,
    'longitude' => $longitude,
  );
  if ($zoom != 'default') {
    $settings['zoom'] = $zoom;
  }
  if ($width != 'default') {
    $settings['width'] = $width;
  }
  if ($height != 'default') {
    $settings['height'] = $height;
  }
  $settings['markers'] = array(
    array(
      'latitude' => $latitude,
      'longitude' => $longitude,
      'markername' => $markername,
      'offset' => 0,
    ),
  );
  if (!empty($info)) {
    $settings['markers'][0]['text'] = $info;
  }
  if ($autoshow) {
    $settings['markers'][0]['autoclick'] = TRUE;
  }
  if (!empty($map)) {
    $settings = array_merge($settings, $map);
  }
  $element = array(
    '#type' => 'gmap',
    '#gmap_settings' => $settings,
  );
  return drupal_render($element);
}