/** * Return the Services_GeoNames with either a mock adapter or the real adapter * depending whether the SERVICES_GEONAMES_LIVETEST environment variable is set * or not. * * @param string $testname The test name (without extension) * @param string $user Username (optional) * @param string $token Auth token (optional) * * @return Services_GeoNames */ function Services_GeoNames_factory($testname, $user = null, $token = null) { $geo = new Services_GeoNames($user, $token); if (!getenv('SERVICES_GEONAMES_LIVETEST')) { // test with a mock adapter $mock = new HTTP_Request2_Adapter_Mock(); if ($testname == 'test_other_04') { $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false); } else { if ($testname == 'test_other_07') { $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false); $mock->addResponse($resp); $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false); $mock->addResponse($resp); $resp = new HTTP_Request2_Response('HTTP/1.1 404 Not Found', false); } else { $resp = new HTTP_Request2_Response('HTTP/1.1 200 Success', false); $file = dirname(__FILE__) . '/data/' . $testname . '.dat'; $resp->appendBody(file_get_contents($file)); } } $mock->addResponse($resp); $geo->getRequest()->setAdapter($mock); } return $geo; }
public function handleTask(&$context) { /* Insert here source code to execute the task */ set_include_path($this->getAdditionalPath('plzservice') . PATH_SEPARATOR . get_include_path()); require_once 'Services/GeoNames.php'; $wsUsername = $this->get("username", $context); $geo = new Services_GeoNames($wsUsername); $postalcode = $this->get("input_plz", $context); $country = $this->get("input_country", $context); if (empty($country) || strlen($country) > 2) { $country = "DE"; } $return = $geo->postalCodeLookup(array("postalcode" => $postalcode, "country" => $country)); if (count($return) == 0) { $state = ""; $country = ""; $city = ""; } else { $return = $return[0]; $state = $return->adminName1; $country = $return->countryCode; $city = $return->placeName; } $fieldCity = $this->get("output_city"); $fieldState = $this->get("output_state"); $fieldCountry = $this->get("output_country"); if (!empty($fieldCity)) { $context->setEnvironment($fieldCity, $city); } if (!empty($fieldState)) { $context->setEnvironment($fieldState, $state); } if (!empty($fieldCountry)) { $context->setEnvironment($fieldCountry, $country); } return "yes"; }
<?php require_once 'Services/GeoNames.php'; $geo = new Services_GeoNames(); $postalCodes = $geo->findNearbyPlaceName(array('placename' => "Salzburg", 'radius' => 10, 'maxRows' => 100)); echo "List of postal codes near by Toulouse in a radius of 10km:\n"; foreach ($postalCodes as $code) { printf(" - %s (%s)\n", $code->postalCode, $code->placeName); } echo "\n";
$abfragebox = mysqli_query($link, sprintf("Select ausbildungsid,ausbildung_" . $lang . ",kurzbezeichnung_" . $lang . ", thema_de From `tl_ausbildungen` order by `reihung` asc")); #Sortierung $sortierer = getParameter('sortierung'); $sortierer2 = getParameter('sortierung'); if ($sortierer == "") { $sortierer = "tp_nachname asc"; } # Therapeut $stherapeut = getParameter('stherapeut'); if ($stherapeut != "") { $sstring = " where tp_nachname = '" . $stherapeut . "' "; } #Umkreis ## Geonames require_once 'pear/geonames/Services/GeoNames.php'; $geo = new Services_GeoNames(); $splz = $_GET['splz']; if ($splz == "" || ctype_digit($splz) == true || $splz == "PLZ bzw. Ort") { $splz = (int) trim($_GET['splz']); } else { $splz = trim($_GET['splz']); } #echo $splz; if ($splz != "" or $splz != "PLZ bzw. Ort") { $umkreis = $_GET['umkreis']; try { $postalCodes = $geo->findNearbyPostalCodes(array('placename' => $splz, 'radius' => $umkreis, 'maxRows' => 200)); #echo "List of postal codes near by in a radius of 10km:\n"; foreach ($postalCodes as $code) { # printf(" - %s (%s)\n", $code->postalCode, $code->placeName); $postleitzahlen = $postleitzahlen . $code->postalCode . ",";
* @category Services * @package Services_GeoNames * @author David Jean Louis <*****@*****.**> * @copyright 2008-2009 David Jean Louis * @license http://opensource.org/licenses/mit-license.php MIT License * @version CVS: $Id: examples1.php 274374 2009-01-23 14:21:59Z izi $ * @link http://pear.php.net/package/Services_GeoNames * @link http://www.geonames.org/export/webservice-exception.html * @since File available since release 0.1.0 * @filesource */ /** * Include the geonames package. */ require_once 'Services/GeoNames.php'; $geo = new Services_GeoNames(); // search for all cities named 'Paris' $cities = $geo->search(array('name_equals' => 'Paris')); echo "List of cities named Paris:\n"; foreach ($cities as $city) { printf(" - %s (%s)\n", $city->name, $city->countryName); } echo "\n"; // find all postal codes near by "Toulouse" in a radius of 10km $postalCodes = $geo->findNearbyPostalCodes(array('lat' => 43.606, 'lng' => 1.444, 'radius' => 10, 'maxRows' => 100)); echo "List of postal codes near by Toulouse in a radius of 10km:\n"; foreach ($postalCodes as $code) { printf(" - %s (%s)\n", $code->postalCode, $code->placeName); } echo "\n"; // get the list of all countries and capitals in spanish