You are here

function ip_geoloc_output_map_current_location in IP Geolocation Views & Maps 7

Same name and namespace in other branches
  1. 8 ip_geoloc_api.inc \ip_geoloc_output_map_current_location()

Outputs an HTML div placeholder into which is injected a map.

The map is centered on the visitor's current location and features a position marker, which when clicked reveals latitude and longitude, as well as the street address and the accuracy of the position shown.

Note this function will result in the visitor being prompted to share their location.

Parameters

string $div_id: id of the div placeholder, can be anything as long as it's unique

string $map_options: as a JSON string e.g '{"mapTypeId":"roadmap", "zoom":15}'

string $map_style: CSS style applied to the div, e.g "height:200px; width:300px"

float $latitude: if empty and HTML5 location retrieval will be initiated

float $longitude: if empty and HTML5 location retrieval will be initiated

string $info_text: optional string to display in the marker balloon, e.g. formatted address

1 call to ip_geoloc_output_map_current_location()
ip_geoloc_map_current_visitor.tpl.php in theme/ip_geoloc_map_current_visitor.tpl.php
ip_geoloc_map_current_visitor.tpl.php

File

./ip_geoloc_api.inc, line 147
API functions of IP geolocation module

Code

function ip_geoloc_output_map_current_location($div_id = 'ip-geoloc-map-current-location', $map_options = NULL, $map_style = NULL, $latitude = NULL, $longitude = NULL, $info_text = NULL) {
  drupal_add_js(IP_GEOLOC_GOOGLE_MAPS, array(
    'type' => 'external',
    'group' => JS_LIBRARY,
  ));
  drupal_add_js(drupal_get_path('module', 'ip_geoloc') . '/js/ip_geoloc_gmap_current_loc.js');
  if (!isset($map_options)) {
    $map_options = IP_GEOLOC_CURRENT_VISITOR_MAP_OPTIONS;
  }
  $settings = array(
    'ip_geoloc_current_location_map_div' => $div_id,
    'ip_geoloc_current_location_map_options' => drupal_json_decode($map_options),
    'ip_geoloc_current_location_map_latlng' => array(
      $latitude,
      $longitude,
    ),
    'ip_geoloc_current_location_map_info_text' => $info_text,
  );
  drupal_add_js($settings, 'setting');
  if (!isset($map_style)) {
    $map_style = IP_GEOLOC_MAP_DIV_DEFAULT_STYLE;
  }
  $map_placeholder = "<div id='{$div_id}'" . (empty($map_style) ? '' : " style='{$map_style}'") . '></div>';
  return $map_placeholder;
}