Services_GeoNames
[ class tree: Services_GeoNames ] [ index: Services_GeoNames ] [ all elements ]

Source for file examples1.php

Documentation is available at examples1.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * This file is part of the PEAR Services_GeoNames package.
  6.  *
  7.  * PHP version 5
  8.  *
  9.  * LICENSE: This source file is subject to the MIT license that is available
  10.  * through the world-wide-web at the following URI:
  11.  * http://opensource.org/licenses/mit-license.php
  12.  *
  13.  * @category  Services
  14.  * @package   Services_GeoNames
  15.  * @author    David Jean Louis <izi@php.net>
  16.  * @copyright 2008-2009 David Jean Louis
  17.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  18.  * @version   CVS: $Id: examples1.php 274374 2009-01-23 14:21:59Z izi $
  19.  * @link      http://pear.php.net/package/Services_GeoNames
  20.  * @link      http://www.geonames.org/export/webservice-exception.html
  21.  * @since     File available since release 0.1.0
  22.  * @filesource
  23.  */
  24.  
  25. /**
  26.  * Include the geonames package.
  27.  */
  28. require_once 'Services/GeoNames.php';
  29.  
  30. $geo = new Services_GeoNames();
  31.  
  32. // search for all cities named 'Paris'
  33. $cities $geo->search(array('name_equals' => 'Paris'));
  34. echo "List of cities named Paris:\n";
  35. foreach ($cities as $city{
  36.     printf(" - %s (%s)\n"$city->name$city->countryName);
  37. }
  38. echo "\n";
  39.  
  40. // find all postal codes near by "Toulouse" in a radius of 10km 
  41. $postalCodes $geo->findNearbyPostalCodes(array(
  42.     'lat'     => 43.606,
  43.     'lng'     => 1.444,
  44.     'radius'  => 10// 10km
  45.     'maxRows' => 100
  46. ));
  47. echo "List of postal codes near by Toulouse in a radius of 10km:\n";
  48. foreach ($postalCodes as $code{
  49.     printf(" - %s (%s)\n"$code->postalCode$code->placeName);
  50. }
  51. echo "\n";
  52.  
  53. // get the list of all countries and capitals in spanish
  54. $countries $geo->countryInfo(array('lang' => 'es'));
  55. echo "List of all countries in spanish language:\n";
  56. foreach ($countries as $country{
  57.     printf(" - %s (capital: %s)\n"$country->countryName$country->capital);
  58. }
  59. echo "\n";
  60.  
  61. // get the neightbours countries of France
  62. $array      $geo->countryInfo(array('country' => 'FR'));
  63. $france     $array[0];
  64. $neighbours $geo->neighbours(array('geonameId' => $france->geonameId));
  65. echo "Neighbours of France are:\n";
  66. foreach ($neighbours as $neighbour{
  67.     printf(" - %s\n"$neighbour->countryName);
  68. }

Documentation generated on Mon, 11 Mar 2019 15:39:14 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.