function ip_geoloc_current_location_ajax_recipient in IP Geolocation Views & Maps 7
Data recipient for javascript function getLocation().
Comes in via menu callback js/ip_geoloc/current_location, see function ip_geoloc_menu() above. Receives latitude, longitude, accuracy and address via the global $_POST variable from function getLocation() in ip_geoloc_current_location.js, which posts these through an AJAX call.
2 string references to 'ip_geoloc_current_location_ajax_recipient'
- ip_geoloc_js_info in ./
ip_geoloc.module - Implements hook_js_info().
- ip_geoloc_menu in ./
ip_geoloc.module - Implements hook_menu().
File
- ./
ip_geoloc.module, line 358 - IPGV&M is a mapping engine for Views that contain locations of entities and/or visitors. Google Maps, Leaflet and OpenLayers2 maps are all supported. and available through this module. Using a number of optional sources IPGV&M also retrieves…
Code
function ip_geoloc_current_location_ajax_recipient() {
if (isset($_POST['error'])) {
// Device/browser does not support getCurrentPosition(), timeout or
// Google reverse-geocode error.
// watchdog() only works at full bootstrap, so store error here and handle
// in ip_geoloc_init() during next click/request.
$error = check_plain($_POST['error']);
_ip_geoloc_set_session_value('error', $error);
drupal_json_output($error);
drupal_exit();
}
// Flesh out $location with the returned street address components.
$location = array(
'ip_address' => ip_address(),
);
foreach ($_POST as $key => $value) {
// Ignore crap required for drupal.org/project/js module
if (drupal_substr($key, 0, 3) !== 'js_') {
$location[check_plain($key)] = check_plain($value);
}
}
$location['provider'] = empty($location['country']) ? 'device' : 'device+google';
$since = _ip_geoloc_get_session_value('position_pending_since');
ip_geoloc_debug(t('IPGV&M: returned from position callback in %since s: !location', array(
'%since' => isset($since) ? number_format(microtime(TRUE) - $since, 1) : '?',
'!location' => ip_geoloc_pretty_print($location),
)));
// If better_statistics module is enabled, we can backfill geolocation
// information to {accesslog} entries occurred since the positioning was
// requested.
if ($since && module_exists('better_statistics')) {
require_once 'plugins/ip_geoloc.statistics.inc';
_ip_geoloc_statistics_backfill($since, $location);
}
if (ip_geoloc_store_location($location) !== FALSE) {
// If successfully stored, don't store again.
$location['ip_address'] = NULL;
}
$location['fixed_address'] = 0;
$location['is_updated'] = TRUE;
// Wipe old location before setting the new one (to avoid merging).
_ip_geoloc_set_session_value('location', NULL);
_ip_geoloc_set_session_value('location', $location);
// Got fresh location so reset 'position_pending_since' timer.
_ip_geoloc_set_session_value('position_pending_since', NULL);
// [#2599950], #6
drupal_json_output('');
drupal_exit();
}