You are here

function location_get_postalcode_data in Location 7.3

Same name and namespace in other branches
  1. 5.3 location.inc \location_get_postalcode_data()
  2. 5 location.inc \location_get_postalcode_data()
  3. 6.3 location.inc \location_get_postalcode_data()
  4. 7.5 location.inc \location_get_postalcode_data()
  5. 7.4 location.inc \location_get_postalcode_data()

Try to extract the the Latitude and Longitude data from the postal code.

Parameters

array $location: Array. the location data -> the values are: 'street' => the string representing the street location (REQUIRED) 'additional' => the string representing the additional street location portion in the location form 'city' => the city name (REQUIRED) 'province' => the province code defined in the country-specific include file 'country' => the lower-case of the two-letter ISO code (REQUIRED) 'postal_code' => the postal-code (REQUIRED)

Return value

array|null Array or NULL. NULL if the delegated-to function that does the actual look-up does not exist. If the appropriate function exists, then this function returns an associative array where 'lon' => A floating point number for the longitude coordinate of the parameter location 'lat' => A floating point number for the latitude coordinate of the parameter location

Related topics

2 calls to location_get_postalcode_data()
location_handler_argument_location_proximity::calculate_coords in handlers/location_handler_argument_location_proximity.inc
Calculate coords.
_location_geo_logic in ./location.module
Perform geocoding logic, etc., prior to storing in the database.

File

./location.inc, line 186
Public API for the Location module.

Code

function location_get_postalcode_data($location = array()) {
  $location['country'] = isset($location['country']) ? trim($location['country']) : NULL;
  $location['postal_code'] = isset($location['postal_code']) ? trim($location['postal_code']) : NULL;
  if (is_null($location['postal_code']) || is_null($location['country']) || empty($location['country']) || empty($location['postal_code']) || $location['postal_code'] == 'xx') {
    return NULL;
  }
  location_load_country($location['country']);
  $country_specific_function = 'location_get_postalcode_data_' . $location['country'];
  if (function_exists($country_specific_function)) {
    return $country_specific_function($location);
  }
  else {
    return NULL;
  }
}