Phirehose::setLocationsByCircle PHP Method

setLocationsByCircle() public method

NOTE: The argument order is Longitude/Latitude (to match the Twitter API and GeoJSON specifications). Eg: setLocationsByCircle(array( array(144.9631, -37.8142, 30), // Melbourne, 3km radius array(-0.1262, 51.5001, 25), // London 10km radius ));
See also: setLocations()
public setLocationsByCircle ( $locations )
    public function setLocationsByCircle($locations)
    {
        $boundingBoxes = array();
        foreach ($locations as $locTriplet) {
            // Sanity check
            if (count($locTriplet) != 3) {
                // Invalid - Not much we can do here but log error
                $this->log('Invalid location triplet for ' . __METHOD__ . ': [' . implode(', ', $locTriplet) . ']', 'error');
                return FALSE;
            }
            list($lon, $lat, $radius) = $locTriplet;
            // Calc bounding boxes
            $maxLat = round($lat + rad2deg($radius / self::EARTH_RADIUS_KM), 2);
            $minLat = round($lat - rad2deg($radius / self::EARTH_RADIUS_KM), 2);
            // Compensate for degrees longitude getting smaller with increasing latitude
            $maxLon = round($lon + rad2deg($radius / self::EARTH_RADIUS_KM / cos(deg2rad($lat))), 2);
            $minLon = round($lon - rad2deg($radius / self::EARTH_RADIUS_KM / cos(deg2rad($lat))), 2);
            // Add to bounding box array
            $boundingBoxes[] = array($minLon, $minLat, $maxLon, $maxLat);
            // Debugging is handy
            $this->log('Resolved location circle [' . $lon . ', ' . $lat . ', r: ' . $radius . '] -> bbox: [' . $minLon . ', ' . $minLat . ', ' . $maxLon . ', ' . $maxLat . ']');
        }
        // Set by bounding boxes
        $this->setLocations($boundingBoxes);
    }