GET geo/search
get-geo-search

GET geo/search

Search for places that can be attached to a Tweet via POST statuses/update. Given a latitude and a longitude pair, an IP address, or a name, this request will return a list of all the valid places that can be used as the place_id when updating a status.

Conceptually, a query can be made from the user's location, retrieve a list of places, have the user validate the location they are 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.

Some parameters in this method are only required based on the existence of other parameters. For instance, "lat" is required if "long" is provided, and vice-versa. Authentication is recommended, but not required with this method.

Resource URL

https://api.twitter.com/1.1/geo/search.json

Resource Information

Response formats JSON
Requires authentication? Yes (user context only)
Rate limited? Yes
Requests / 15-min window (user auth) 15

Parameters

Name Required Description Default Value Example
lat optional The latitude to search around. This parameter will be ignored unless it is inside the range -90.0 to +90.0 (North is positive) inclusive. It will also be ignored if there isn't a corresponding long parameter. 37.7821120598956
long optional The longitude to search around. The valid ranges for longitude are -180.0 to +180.0 (East is positive) inclusive. This parameter will be ignored if outside that range, if it is not a number, if geo_enabled is turned off, or if there not a corresponding lat parameter. -122.400612831116
query optional Free-form text to match against while executing a geo-based query, best suited for finding nearby locations by name. Remember to URL encode the query. Twitter%20HQ
ip optional An IP address. Used when attempting to fix geolocation based off of the user's IP address. 74.125.19.104
granularity optional

This is the minimal granularity of place types to return and must be one of: neighborhood , city , admin or country. If no granularity is provided for the request neighborhood is assumed.

Setting this to city, for example, will find places which have a type of city, admin or country.

neighborhood

city
max_results optional A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here. 3

Example Request

twurl /1.1/geo/search.json?query=Toronto&granularity=neighborhood&trim_place=false

Example Response

{
    "result": {
        "places": [{
            "id": "3797791ff9c0e4c6",
            "url": "https://api.twitter.com/1.1/geo/id/3797791ff9c0e4c6.json",
            "place_type": "city",
            "name": "Toronto",
            "full_name": "Toronto, Ontario",
            "country_code": "CA",
            "country": "Canada",
            "centroid": [-79.27828265214646, 43.629311],
            "bounding_box": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [-79.639319, 43.403221],
                        [-79.639319, 43.855401],
                        [-78.90582, 43.855401],
                        [-78.90582, 43.403221],
                        [-79.639319, 43.403221]
                    ]
                ]
            }
        },
    {
            "id": "53d949149e8cd438",
            "url": "https://api.twitter.com/1.1/geo/id/53d949149e8cd438.json",
            "place_type": "city",
            "name": "Toronto",
            "full_name": "Toronto, OH",
            "country_code": "US",
            "country": "United States",
            "centroid": [-80.60069343486651, 40.4671546],
            "bounding_box": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [-80.63881, 40.424414],
                        [-80.63881, 40.5075722],
                        [-80.594794, 40.5075722],
                        [-80.594794, 40.424414],
                        [-80.63881, 40.424414]
                    ]
                ]
            }
        }, {
            "id": "54462d87587b84cb",
            "url": "https://api.twitter.com/1.1/geo/id/54462d87587b84cb.json",
            "place_type": "neighborhood",
            "name": "Toronto",
            "full_name": "Toronto, Newcastle",
            "country_code": "AU",
            "country": "Australia",
            "centroid": [151.57840022539824, -33.01424496],
            "bounding_box": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [151.55590104, -33.03195696],
                        [151.55590104, -32.99653296],
                        [151.60682412, -32.99653296],
                        [151.60682412, -33.03195696],
                        [151.55590104, -33.03195696]
                    ]
                ]
            }
        }, {
            "id": "3b4ce0fc1393cb76",
            "url": "https://api.twitter.com/1.1/geo/id/3b4ce0fc1393cb76.json",
            "place_type": "city",
            "name": "Toronto",
            "full_name": "Toronto, England",
            "country_code": "GB",
            "country": "United Kingdom",
            "centroid": [-1.6909451571222085, 54.67073205],
            "bounding_box": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [-1.6997633, 54.6675502],
                        [-1.6997633, 54.6739139],
                        [-1.6863727, 54.6739139],
                        [-1.6863727, 54.6675502],
                        [-1.6997633, 54.6675502]
                    ]
                ]
            }
        }, {
            "id": "0088844f399ec5c3",
            "url": "https://api.twitter.com/1.1/geo/id/0088844f399ec5c3.json",
            "place_type": "neighborhood",
            "name": "New Toronto",
            "full_name": "New Toronto, Toronto",
            "country_code": "CA",
            "country": "Canada",
            "centroid": [-79.51197387150921, 43.6002065],
            "bounding_box": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [-79.526473, 43.587097],
                        [-79.526473, 43.613316],
                        [-79.49687, 43.613316],
                        [-79.49687, 43.587097],
                        [-79.526473, 43.587097]
                    ]
                ]
            }
        }]
    },
    "query": {
        "url": "https://api.twitter.com/1.1/geo/search.json?query=Toronto",
        "type": "search",
        "params": {
            "granularity": "neighborhood",
            "query": "Toronto",
            "trim_place": false
        }
    }
}```