You are here

function location_nearby_postalcodes_bylatlon in Location 5

Takes a latitude, longitude, and a distance, and returns all postal_codes within

Parameters

$lon: A floating point of the longitude coordinate of the search point

$lat: A floating point of the latitude coordinate of the search point

$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 contatenation of the country's ISO code and the postal code. For example, if one of the search results is for postal code "94803" in the United States, the key is then "us94803" -> 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. '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 array 'distance_unit' => The unit of distance specified by 'distance'

File

./location.inc, line 680

Code

function location_nearby_postalcodes_bylatlon($lon, $lat, $distance, $distance_unit = 'km') {

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

  //$start_time = microtime();

  // If the given $lon/$lat don't make sense, return an empty search result set.
  if (!is_numeric($lon) || !is_numeric($lat)) {
    return array();
  }

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

  // 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;
}