php - How to use static function inside CI library? -


i have wound this great resource on calculating bounding coordinates , calculating distance between 2 points on earth sphere.

i had started build own ci library when wound this. love adjust use lost on how it.

there example on bounding coordinates:

$edison = geolocation::fromdegrees(40.5187154, -74.4120953); $coordinates = $edison->boundingcoordinates(3, 'miles'); 

the question - if use class library, how call it?

$edison = $this->geolibrary->geolocation::fromdegrees(40.5187154, -74.4120953); 

?

or how should change code use library?

update:

code library:

<?php if (!defined('basepath')) exit('no direct script access allowed');  class geolocation {      private $radlat;  // latitude in radians     private $radlon;  // longitude in radians      private $deglat;     // latitude in degrees     private $deglon;  // longitude in degrees      private $angular; // angular radius      const earths_radius_km = 6371.01;     const earths_radius_mi = 3958.762079;      protected static $min_lat;  // -pi/2     protected static $max_lat;  //  pi/2     protected static $min_lon;  // -pi     protected static $max_lon;  //  pi      public function __construct() {         self::$min_lat = deg2rad(-90);   // -pi/2         self::$max_lat = deg2rad(90);    //  pi/2         self::$min_lon = deg2rad(-180);  // -pi         self::$max_lon = deg2rad(180);   //  pi     }      public function createlocation($latitude, $longitude, $from)     {         // want create instance here ???     }      /**      * @param double $latitude latitude, in degrees.      * @param double $longitude longitude, in degrees.      * @return geolocation      */     private static function fromdegrees($latitude, $longitude) {         $location = new geolocation();         $location->radlat = deg2rad($latitude);         $location->radlon = deg2rad($longitude);         $location->deglat = $latitude;         $location->deglon = $longitude;         $location->checkbounds();         return $location;     }      /**      * @param double $latitude latitude, in radians.      * @param double $longitude longitude, in radians.      * @return geolocation      */     private static function fromradians($latitude, $longitude) {         $location = new geolocation();         $location->radlat = $latitude;         $location->radlon = $longitude;         $location->deglat = rad2deg($latitude);         $location->deglon = rad2deg($longitude);         $location->checkbounds();         return $location;     }      protected function checkbounds() {         if ($this->radlat < self::$min_lat || $this->radlat > self::$max_lat ||                 $this->radlon < self::$min_lon || $this->radlon > self::$max_lon)             throw new \exception("invalid argument");     }    /**    * computes great circle distance between geolocation instance    * , location argument.    * @param geolocation $location    * @param string $unit_of_measurement    * @internal param float $radius radius of sphere, e.g. average radius    * spherical approximation of figure of earth approximately    * 6371.01 kilometers.    * @return double distance, measured in same unit radius    * argument.    */     public function distanceto(geolocation $location, $unit_of_measurement) {         $radius = $this->getearthsradius($unit_of_measurement);          return acos(sin($this->radlat) * sin($location->radlat) +                     cos($this->radlat) * cos($location->radlat) *                     cos($this->radlon - $location->radlon)) * $radius;     }      /**      * @return double latitude, in degrees.      */     public function getlatitudeindegrees() {         return $this->deglat;     }      /**      * @return double longitude, in degrees.      */     public function getlongitudeindegrees() {         return $this->deglon;     }      /**      * @return double latitude, in radians.      */     public function getlatitudeinradians() {         return $this->radlat;     }      /**      * @return double longitude, in radians.      */     public function getlongitudeinradians() {         return $this->radlon;     }      /**      * @return double angular radius.      */     public function getangular() {         return $this->angular;     }      public function __tostring() {         return "(" . $this->deglat . ", " . $this->deglon . ") = (" .                 $this->radlat . " rad, " . $this->radlon . " rad";     }     /**    * <p>computes bounding coordinates of points on surface    * of sphere have great circle distance point represented    * geolocation instance less or equal distance    * argument.</p>    * <p>for more information formulae used in method visit    * <a href="http://janmatuschek.de/latitudelongitudeboundingcoordinates">    * http://janmatuschek.de/latitudelongitudeboundingcoordinates</a>.</p>    *    * @param double $distance distance point represented    * geolocation instance. must me measured in same unit radius    * argument.    * @param string $unit_of_measurement    * @throws \exception    * @internal param radius radius of sphere, e.g. average radius    * spherical approximation of figure of earth approximately    * 6371.01 kilometers.    * @return geolocation[] array of 2 geolocation objects such that:<ul>    * <li>the latitude of point within specified distance greater    * or equal latitude of first array element , smaller or    * equal latitude of second array element.</li>    * <li>if longitude of first array element smaller or equal    * longitude of second element,    * longitude of point within specified distance greater    * or equal longitude of first array element , smaller or    * equal longitude of second array element.</li>    * <li>if longitude of first array element greater    * longitude of second element (this case if 180th    * meridian within distance),    * longitude of point within specified distance greater    * or equal longitude of first array element    * <strong>or</strong> smaller or equal longitude of second    * array element.</li>    * </ul>    */     public function boundingcoordinates($distance, $unit_of_measurement) {         $radius = $this->getearthsradius($unit_of_measurement);         if ($radius < 0 || $distance < 0) throw new \exception('arguments must greater 0.');          // angular distance in radians on great circle         $this->angular = $distance / $radius;          $minlat = $this->radlat - $this->angular;         $maxlat = $this->radlat + $this->angular;          $minlon = 0;         $maxlon = 0;         if ($minlat > self::$min_lat && $maxlat < self::$max_lat) {             $deltalon = asin(sin($this->angular) /                 cos($this->radlat));             $minlon = $this->radlon - $deltalon;             if ($minlon < self::$min_lon) $minlon += 2 * pi();             $maxlon = $this->radlon + $deltalon;             if ($maxlon > self::$max_lon) $maxlon -= 2 * pi();         } else {             // pole within distance             $minlat = max($minlat, self::$min_lat);             $maxlat = min($maxlat, self::$max_lat);             $minlon = self::$min_lon;             $maxlon = self::$max_lon;         }          return array(             geolocation::fromradians($minlat, $minlon),              geolocation::fromradians($maxlat, $maxlon)         );     }      protected function getearthsradius($unit_of_measurement) {         $u = $unit_of_measurement;         if($u == 'miles' || $u == 'mi')             return $radius = self::earths_radius_mi;         elseif($u == 'kilometers' || $u == 'km')             return $radius = self::earths_radius_km;          else throw new \exception('you must supply valid unit of measurement');     }     /**      *  retrieves geocoding information google      *  eg. $response = geolocation::getgeocodefromgoogle($location);      *      $latitude = $response->results[0]->geometry->location->lng;      *      $longitude = $response->results[0]->geometry->location->lng;      *  @param string $location address, city, state, etc.      *  @return \stdclass      */     public static function getgeocodefromgoogle($location) {         $url = 'http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($location).'&sensor=false';         $ch = curl_init();         curl_setopt($ch, curlopt_url,$url);         curl_setopt($ch, curlopt_returntransfer, true);         return json_decode(curl_exec($ch));     }     public static function milestokilometers($miles) {         return $miles * 1.6093439999999999;     }     public static function kilometerstomiles($km) {         return $km * 0.621371192237334;     } } 

i want create function createlocation use library this:

$this->load->library('geolocation'); $lat=$this->input->post('latitude'); $lng=$this->input->post('longitude'); $radius=$this->input->post('radiuss'); $user_center = $this->geolocation->createlocation($lat, $lng); $boundingcoordinates = $user_center->boundingcoordinates($radius, 'kilometers'); 

i tried:

public function createlocation($latitude, $longitude)     {         $loc = geolocation::fromdegrees($latitude, $longitude);         return $loc;     } 

but undefined property: alerts::$geolocation on line createlocation function.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -