You are here

function location_nearby_postalcodes_bylocation in Location 5

Takes an location and a distance and returns an array of all postal-codes (from all countries that are supported) within the specified distance of the specified location.

Parameters

$location : An associative array where 'street' => the street location 'additional' => extra street location or building name or hall or something like that.\ 'city' => a city name 'province' => province code as defined by the country specific include file 'country' => lower-cased two-letter ISO 3166 code (REQUIRED) 'postal_code' => the postal_code

$distance: The number portion of the distance; it is forced to an integer ceiling

$distance_unit : The unit of distance being used for the distance being submitted. Valid arguments for $distance_unit are 'mile' and 'km'. If something other than one of these unit types is submitted for this argument, it is forced to 'km'.

Return value

An array where -> the keys are a postive integer ranking of the search result's closeness to the parameter $postal_code with 1 being assigned to the nearest postal code -> the values are an associative array where 'postal_code' => A postal code that fell within the search-radius given by $distance and $distance_unit. 'country' => The two-letter ISO code for the home-country of this particular postal_code search result. 'city' => The city to which this postal code belongs. 'province' => The province to which this postal code belongs. 'lon' => The longitude coordinate of the approximate center of the area covered by 'postal_code' 'lat' => The latitude coordinate of the approximate center of the area covered by 'postal_code' 'distance' => The number of 'km's or 'mile's that are between the approximate center of the area of the $postal_code parameter and that of the 'postal_code' in this subarray 'distance_unit' => The unit of distance specified by 'scalar'

File

./location.inc, line 617

Code

function location_nearby_postalcodes_bylocation($location, $distance, $distance_unit = 'km') {

  // DEBUG: commented code is for testing/debugging purposes

  //$start_time = microtime();
  $latlon = location_latlon_rough($location);

  // If we could not get lat/lon coordinates for the given location, return an empty search result set.
  if (!isset($latlon['lat']) || !isset($latlon['lon'])) {
    return array();
  }

  // If the distance parameters did not make sense, return an empty search result set.
  if (!($distance_float = _location_convert_distance_to_meters($distance, $distance_unit))) {
    return array();
  }
  $search_results = _location_nearby_postalcodes($latlon['lon'], $latlon['lat'], $distance_float);

  //DEBUG: commented code is for testing/debugging

  //$format_start_time = microtime();
  _location_format_search_result_distances($search_results, $distance_unit);

  //$format_end_time = microtime();

  //print 'Time for FORMATTING to complete: '. _location_time_difference($format_end_time, $format_start_time) ."<br/>\n";

  // DEBUG: commented code is for testing/debugging purposes

  //$end_time = microtime();

  //print 'Time for this search to complete: '. _location_time_difference($end_time, $start_time) ."<br/>\n";
  return $search_results;
}