TijsVerkoyen\Twitter\Twitter::geoSearch PHP Method

geoSearch() public method

Conceptually, a query can be made from the user's location, retrieve a list of places, have the user validate the location he or she is at, and then send the ID of this location with a call to POST statuses/update. This is the recommended method to use find places that can be attached to statuses/update. Unlike GET geo/reverse_geocode which provides raw data access, this endpoint can potentially re-order places with regards to the user who is authenticated. This approach is also preferred for interactive place matching with the user.
public geoSearch ( float[optional] $lat = null, float[optional] $long = null, string[optional] $query = null, string[optional] $ip = null, string[optional] $granularity = null, string[optional] $accuracy = null, int[optional] $maxResults = null, string[optional] $containedWithin = null, array $attributes = null ) : array
$lat float[optional]
$long float[optional]
$query string[optional]
$ip string[optional]
$granularity string[optional]
$accuracy string[optional]
$maxResults int[optional]
$containedWithin string[optional]
$attributes array
return array
    public function geoSearch($lat = null, $long = null, $query = null, $ip = null, $granularity = null, $accuracy = null, $maxResults = null, $containedWithin = null, array $attributes = null)
    {
        // build parameters
        $parameters = array();
        if ($lat != null) {
            $parameters['lat'] = (double) $lat;
        }
        if ($long != null) {
            $parameters['long'] = (double) $long;
        }
        if ($query != null) {
            $parameters['query'] = (string) $query;
        }
        if ($ip != null) {
            $parameters['ip'] = (string) $ip;
        }
        if ($accuracy != null) {
            $parameters['accuracy'] = (string) $accuracy;
        }
        if ($granularity != null) {
            $parameters['granularity'] = (string) $granularity;
        }
        if ($maxResults != null) {
            $parameters['max_results'] = (int) $maxResults;
        }
        if ($containedWithin != null) {
            $parameters['contained_within'] = (string) $containedWithin;
        }
        if ($attributes != null) {
            foreach ($attributes as $key => $value) {
                $parameters['attribute:' . $key] = (string) $value;
            }
        }
        // make the call
        return $this->doCall('geo/search.json', $parameters);
    }

Usage Example

 /**
  * Tests Twitter->geoSearch()
  */
 public function testGeoSearch()
 {
     $response = $this->twitter->geoSearch(37.7821120598956, -122.400612831116);
     $this->assertArrayHasKey('result', $response);
     $this->assertArrayHasKey('places', $response['result']);
     foreach ($response['result']['places'] as $row) {
         $this->isPlace($row);
     }
     $this->assertArrayHasKey('query', $response);
     $this->assertArrayHasKey('type', $response['query']);
     $this->assertArrayHasKey('params', $response['query']);
     $this->assertArrayHasKey('coordinates', $response['query']['params']);
     $this->assertArrayHasKey('autocomplete', $response['query']['params']);
     $this->assertArrayHasKey('accuracy', $response['query']['params']);
     $this->assertArrayHasKey('granularity', $response['query']['params']);
     $this->assertArrayHasKey('query', $response['query']['params']);
     $this->assertArrayHasKey('url', $response['query']);
 }
Twitter