private function subdivide($url, $parameters)
    {
        if ($this->subradius < 200)
        {
            throw new \Exception('Subradius should be at least 200 meters.');
        }

        $quotient = $parameters['radius'] / $this->subradius;

        if ($parameters['radius'] % $this->subradius || $quotient % 2)
        {
            throw new \Exception('Subradius should divide evenly into radius.');
        }

        $center    = explode(',', $parameters['location']);
        $centerlat = $center[0];
        $centerlng = $center[1];
        $count     = $quotient;
        $lati      = $this->meters2lat($this->subradius * 2);

        $this->grid['results'] = array();

        for ($i = $count / 2 * -1; $i <= $count / 2; $i++)
        {
            $lat  = $centerlat + $i * $lati;
            $lngi = $this->meters2lng($this->subradius * 2, $lat);

            for ($j = $count / 2 * -1; $j <= $count / 2; $j++)
            {
                $lng = $centerlng + $j * $lngi;
                $loc = $lat . ',' . $lng;

                $parameters['location'] = $loc;
                $parameters['radius']   = $this->subradius;

                $pagetoken = true;

                while ($pagetoken)
                {
                    $this->queryGoogle($url, $parameters);

                    $this->grid[$i][$j] = $this->response;

                    $this->grid['results'] = array_merge(
                        $this->grid['results'],
                        $this->response['results']
                    );

                    if (isset($this->response['next_page_token']))
                    {
                        $this->pagetoken = $this->response['next_page_token'];
                    }
                    else
                    {
                        $this->pagetoken = null;
                        $pagetoken       = false;
                    }
                }
            }
        }

        return $this->grid;
    }
private function subdivide($url, $parameters)
    {
        if ($this->subradius < 200)
        {
            throw new \Exception('Subradius should be at least 200 meters.');
        }

        $quotient = $parameters['radius'] / $this->subradius;

        if ($parameters['radius'] % $this->subradius || $quotient % 2)
        {
            throw new \Exception('Subradius should divide evenly into radius.');
        }

        $center    = explode(',', $parameters['location']);
        $centerlat = $center[0];
        $centerlng = $center[1];
        $count     = $quotient;
        $lati      = $this->meters2lat($this->subradius * 2);

        $this->grid['results'] = array();

        for ($i = $count / 2 * -1; $i <= $count / 2; $i++)
        {
            $lat  = $centerlat + $i * $lati;
            $lngi = $this->meters2lng($this->subradius * 2, $lat);

            for ($j = $count / 2 * -1; $j <= $count / 2; $j++)
            {
                $lng = $centerlng + $j * $lngi;
                $loc = $lat . ',' . $lng;

                $parameters['location'] = $loc;
                $parameters['radius']   = $this->subradius;

                $pagetoken = true;

                while ($pagetoken)
                {
                    $this->queryGoogle($url, $parameters);

                    $this->grid[$i][$j] = $this->response;

                    $this->grid['results'] = array_merge(
                        $this->grid['results'],
                        $this->response['results']
                    );

                    if (isset($this->response['next_page_token']))
                    {
                        $this->pagetoken = $this->response['next_page_token'];
                    }
                    else
                    {
                        $this->pagetoken = null;
                        $pagetoken       = false;
                    }
                }
            }
        }

        return $this->grid;
    }
private function subdivide ( $ url , $ parameters ) { if ( $ this -> subradius < 200 ) { throw new \ Exception ( 'Subradius should be at least 200 meters.' ) ; } $ quotient = $ parameters [ 'radius' ] / $ this -> subradius ; if ( $ parameters [ 'radius' ] % $ this -> subradius || $ quotient % 2 ) { throw new \ Exception ( 'Subradius should divide evenly into radius.' ) ; } $ center = explode ( ',' , $ parameters [ 'location' ] ) ; $ centerlat = $ center [ 0 ] ; $ centerlng = $ center [ 1 ] ; $ count = $ quotient ; $ lati = $ this -> meters2lat ( $ this -> subradius * 2 ) ; $ this -> grid [ 'results' ] = array ( ) ; for ( $ i = $ count / 2 * - 1 ; $ i <= $ count / 2 ; $ i ++ ) { $ lat = $ centerlat + $ i * $ lati ; $ lngi = $ this -> meters2lng ( $ this -> subradius * 2 , $ lat ) ; for ( $ j = $ count / 2 * - 1 ; $ j <= $ count / 2 ; $ j ++ ) { $ lng = $ centerlng + $ j * $ lngi ; $ loc = $ lat . ',' . $ lng ; $ parameters [ 'location' ] = $ loc ; $ parameters [ 'radius' ] = $ this -> subradius ; $ pagetoken = true ; while ( $ pagetoken ) { $ this -> queryGoogle ( $ url , $ parameters ) ; $ this -> grid [ $ i ] [ $ j ] = $ this -> response ; $ this -> grid [ 'results' ] = array_merge ( $ this -> grid [ 'results' ] , $ this -> response [ 'results' ] ) ; if ( isset ( $ this -> response [ 'next_page_token' ] ) ) { $ this -> pagetoken = $ this -> response [ 'next_page_token' ] ; } else { $ this -> pagetoken = null ; $ pagetoken = false ; } } } } return $ this -> grid ; }
Returns the aggregated responses for a subdivided search
Returns the aggregated responses for a subdivided search