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

Source for file Location.php

Documentation is available at Location.php

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP version 5                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (C) 2004 MaxMind LLC                                       |
  6. // +----------------------------------------------------------------------+
  7. // | This library is free software; you can redistribute it and/or        |
  8. // | modify it under the terms of the GNU Lesser General Public           |
  9. // | License as published by the Free Software Foundation; either         |
  10. // | version 2.1 of the License, or (at your option) any later version.   |
  11. // |                                                                      |
  12. // | This library is distributed in the hope that it will be useful,      |
  13. // | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
  14. // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    |
  15. // | Lesser General Public License for more details.                      |
  16. // |                                                                      |
  17. // | You should have received a copy of the GNU Lesser General Public     |
  18. // | License along with this library; if not, write to the Free Software  |
  19. // | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 |
  20. // | USA, or view it online at http://www.gnu.org/licenses/lgpl.txt.      |
  21. // +----------------------------------------------------------------------+
  22. // | Authors: Jim Winstead <jimw@apache.org> (original Maxmind version)   |
  23. // |          Hans Lellelid <hans@xmpl.org>                               |
  24. // +----------------------------------------------------------------------+
  25. //
  26. // $Id: Location.php,v 1.1 2004/07/01 12:51:13 hlellelid Exp $
  27.  
  28. /**
  29.  * This class represents a location record as returned by Net_GeoIP::lookupLocation().
  30.  * 
  31.  * This class is primarily a collection of values (the public properties of the class), but
  32.  * there is also a distance() method to calculate the km distance between two points.
  33.  * 
  34.  * @author Hans Lellelid <hans@xmpl.org>
  35.  * @version $Revision: 1.1 $
  36.  * @package Net_GeoIP
  37.  * @see Net_GeoIP::lookupLocation()
  38.  */
  39. {
  40.  
  41.     public $countryCode;
  42.     public $countryName;
  43.     public $region;
  44.     public $city;
  45.     public $postalCode;
  46.     public $latitude;
  47.     public $longitude;
  48.     public $areaCode;
  49.     public $dmaCode;
  50.           
  51.     /**
  52.      * Calculate the distance in km between two points.
  53.      * @param Net_GeoIP_Location $loc The other point to which distance will be calculated.
  54.      * @return float The number of km between two points on the globe.
  55.      */
  56.     public function distance(Net_GeoIP_Location $loc)
  57.     {        
  58.         // ideally these should be class constants, but class constants 
  59.         // can't be operations.
  60.         $RAD_CONVERT = M_PI / 180;
  61.         $EARTH_DIAMETER = 2 * 6378.2;
  62.         
  63.         $lat1 $this->latitude;
  64.         $lon1 $this->longitude;
  65.         $lat2 $loc->latitude;
  66.         $lon2 $loc->longitude;
  67.  
  68.         // convert degrees to radians
  69.         $lat1 *= $RAD_CONVERT;
  70.         $lat2 *= $RAD_CONVERT;
  71.  
  72.         // find the deltas
  73.         $delta_lat $lat2 $lat1;
  74.         $delta_lon ($lon2 $lon1$RAD_CONVERT;
  75.  
  76.         // Find the great circle distance
  77.         $temp pow(sin($delta_lat/2)2cos($lat1cos($lat2pow(sin($delta_lon/2)2);
  78.         return $EARTH_DIAMETER atan2(sqrt($temp),sqrt(1-$temp));
  79.     }
  80.                 
  81. }

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