You are here

function ip_geoloc_format_address in IP Geolocation Views & Maps 8

Same name and namespace in other branches
  1. 7 ip_geoloc.module \ip_geoloc_format_address()

Poor man's address formatter.

It doesn't take local format conventions into account. Luckily this is only called as a fallback when lat/long could not be established or the Google reverse-geocode function returned an error.

Parameters

array $location: Array of location components.

3 calls to ip_geoloc_format_address()
IpGeoLocGlobal::useGeoipApiIfEnabled in src/Services/IpGeoLocGlobal.php
Module GeoIP API does not expose a hook, but it does expose an API.
ip_geoloc_smart_ip_get_location_alter in ./ip_geoloc.module
Implements hook_smart_ip_get_location_alter().
ip_geoloc_use_geoip_api_if_enabled in ./ip_geoloc.module
Module GeoIP API does not expose a hook, but it does expose an API.

File

./ip_geoloc.module, line 483
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_format_address(array &$location) {
  $location['formatted_address'] = isset($location['city']) ? $location['city'] : '';
  if (!empty($location['region'])) {
    $location['formatted_address'] .= ' ' . $location['region'];
  }
  if (!empty($location['postal_code']) && $location['postal_code'] != '-') {
    $location['formatted_address'] .= ' ' . $location['postal_code'] . ',';
  }
  if (!empty($location['country'])) {
    $location['formatted_address'] .= ' ' . $location['country'];
  }
  $location['formatted_address'] = trim($location['formatted_address']);
}