pbx_cities_lat_lng() -- a custom function in pbx_cities_lat_lng.php
Esta página está disponible sólo en inglés.
<?php /** * PHP By Example * * @copyright 2014 Michel Corne * @license http://www.opensource.org/licenses/gpl-3.0.html GNU GPL v3 */
/** * Converts a latitude or longitude to a signed float * * @param string $coordinate eg "51°29'N", or "0°00'E/W" * @return float */ function pbx_coordinate_to_float($coordinate) { if (! preg_match("~^(\d+)°(\d+)'([NESW])~", $coordinate, $match)) { return null; }
if ($direction == 'S' or $direction == 'W') { $coordinate = -$coordinate; }
return $coordinate; }
/** * Returns the latitude and longitude of a city * * @param string $city eg "Aberdeen, United Kingdom, Scotland", or "Aberdeen, United Kingdom", or "Aberdeen" * @return array latitude and longitude, or null for both */ function pbx_get_city_lat_lng($city) { $pieces = preg_split('~[,;:/+| ]+~', $city, -1, PREG_SPLIT_NO_EMPTY); $indexed_lat_lng = pbx_index_lat_lng();
if ($state) { $indexed_lat_lng[$city][$country][$state][] = $lat_lng; } } }
return $indexed_lat_lng; }
/** * Loads the latitudes and longitudes of the major cities * * @return array * @see https://code.google.com/p/php-by-example/source/browse/trunk/application/custom/cities-lat-lng.csv * @see http://en.wikipedia.org/wiki/List_of_cities_by_longitude#Sources */ function pbx_load_cities_lat_lng() { static $cities_lat_lng;
/** * Provides access to the functions above through class or object methods * * This class is used for unit testing. * */ class pbx_cities_lat_lng { function __call($name, $arguments) { return call_user_func_array(self::$name, $arguments); }
static function coordinate_to_float($coordinate) { return pbx_coordinate_to_float($coordinate); }
static function get_city_lat_lng($city) { return pbx_get_city_lat_lng($city); }
static function get_city_names() { return pbx_get_city_names(); }
static function index_lat_lng() { return pbx_index_lat_lng(); }
static function load_cities_lat_lng() { return pbx_load_cities_lat_lng(); } }