GET geo/search

Updated on Wed, 2013-08-21 11:17

Search for places that can be attached to a 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 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.

Resource URL

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

Parameters

Note: At least one of the following parameters must be provided to this resource: lat, long, ip, or query

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.

Example Values: 37.7821120598956

long optional

The longitude to search around. The valid ranges for longitude is -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 disabled, or if there not a corresponding lat parameter.

Example Values: -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.

Example Values: Twitter%20HQ

ip optional

An IP address. Used when attempting to fix geolocation based off of the user's IP address.

Example Values: 74.125.19.104

granularity optional

This is the minimal granularity of place types to return and must be one of: poi, 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.

Example Values: city

accuracy optional

A hint on the "region" in which to search. If a number, then this is a radius in meters, but it can also take a string that is suffixed with ft to specify feet. If this is not passed in, then it is assumed to be 0m. If coming from a device, in practice, this value is whatever accuracy the device has measuring its location (whether it be coming from a GPS, WiFi triangulation, etc.).

Example Values: 5ft

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.

Example Values: 3

attribute:street_address optional

This parameter searches for places which have this given street address. There are other well-known, and application specific attributes available. Custom attributes are also permitted. Learn more about Place Attributes.

Example Values: 795%20Folsom%20St

callback optional

If supplied, the response will use the JSONP format with a callback of the given name.

Extended description

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.

Example Request

GET

https://api.twitter.com/1.1/geo/search.json?query=Toronto

  1. {
  2.   "query": {
  3.     "params": {
  4.       "accuracy": 0, 
  5.       "autocomplete": false, 
  6.       "granularity": "neighborhood", 
  7.       "query": "Toronto", 
  8.       "trim_place": false
  9.     }, 
  10.     "type": "search", 
  11.     "url": "https://api.twitter.com/1.1/geo/search.json?accuracy=0&query=Toronto&granularity=neighborhood&autocomplete=false&trim_place=false"
  12.   }, 
  13.   "result": {
  14.     "places": [
  15.       {
  16.         "attributes": {}, 
  17.         "bounding_box": {
  18.           "coordinates": [
  19.             [
  20.               [
  21.                 -96.647415, 
  22.                 44.566715
  23.               ], 
  24.               [
  25.                 -96.630435, 
  26.                 44.566715
  27.               ], 
  28.               [
  29.                 -96.630435, 
  30.                 44.578118
  31.               ], 
  32.               [
  33.                 -96.647415, 
  34.                 44.578118
  35.               ]
  36.             ]
  37.           ], 
  38.           "type": "Polygon"
  39.         }, 
  40.         "contained_within": [
  41.           {
  42.             "attributes": {}, 
  43.             "bounding_box": {
  44.               "coordinates": [
  45.                 [
  46.                   [
  47.                     -104.057739, 
  48.                     42.479686
  49.                   ], 
  50.                   [
  51.                     -96.436472, 
  52.                     42.479686
  53.                   ], 
  54.                   [
  55.                     -96.436472, 
  56.                     45.945716
  57.                   ], 
  58.                   [
  59.                     -104.057739, 
  60.                     45.945716
  61.                   ]
  62.                 ]
  63.               ], 
  64.               "type": "Polygon"
  65.             }, 
  66.             "country": "United States", 
  67.             "country_code": "US", 
  68.             "full_name": "South Dakota, US", 
  69.             "id": "d06e595eb3733f42", 
  70.             "name": "South Dakota", 
  71.             "place_type": "admin", 
  72.             "url": "https://api.twitter.com/1.1/geo/id/d06e595eb3733f42.json"
  73.           }
  74.         ], 
  75.         "country": "United States", 
  76.         "country_code": "US", 
  77.         "full_name": "Toronto, SD", 
  78.         "id": "3e8542a1e9f82870", 
  79.         "name": "Toronto", 
  80.         "place_type": "city", 
  81.         "url": "https://api.twitter.com/1.1/geo/id/3e8542a1e9f82870.json"
  82.       }, 
  83.       {
  84.         "attributes": {}, 
  85.         "bounding_box": {
  86.           "coordinates": [
  87.             [
  88.               [
  89.                 -80.622815, 
  90.                 40.436469
  91.               ], 
  92.               [
  93.                 -80.596567, 
  94.                 40.436469
  95.               ], 
  96.               [
  97.                 -80.596567, 
  98.                 40.482566
  99.               ], 
  100.               [
  101.                 -80.622815, 
  102.                 40.482566
  103.               ]
  104.             ]
  105.           ], 
  106.           "type": "Polygon"
  107.         }, 
  108.         "contained_within": [
  109.           {
  110.             "attributes": {}, 
  111.             "bounding_box": {
  112.               "coordinates": [
  113.                 [
  114.                   [
  115.                     -84.820305, 
  116.                     38.403423
  117.                   ], 
  118.                   [
  119.                     -80.518454, 
  120.                     38.403423
  121.                   ], 
  122.                   [
  123.                     -80.518454, 
  124.                     42.327132
  125.                   ], 
  126.                   [
  127.                     -84.820305, 
  128.                     42.327132
  129.                   ]
  130.                 ]
  131.               ], 
  132.               "type": "Polygon"
  133.             }, 
  134.             "country": "United States", 
  135.             "country_code": "US", 
  136.             "full_name": "Ohio, US", 
  137.             "id": "de599025180e2ee7", 
  138.             "name": "Ohio", 
  139.             "place_type": "admin", 
  140.             "url": "https://api.twitter.com/1.1/geo/id/de599025180e2ee7.json"
  141.           }
  142.         ], 
  143.         "country": "United States", 
  144.         "country_code": "US", 
  145.         "full_name": "Toronto, OH", 
  146.         "id": "53d949149e8cd438", 
  147.         "name": "Toronto", 
  148.         "place_type": "city", 
  149.         "url": "https://api.twitter.com/1.1/geo/id/53d949149e8cd438.json"
  150.       }, 
  151.       {
  152.         "attributes": {}, 
  153.         "bounding_box": {
  154.           "coordinates": [
  155.             [
  156.               [
  157.                 -79.639128, 
  158.                 43.403221
  159.               ], 
  160.               [
  161.                 -78.90582, 
  162.                 43.403221
  163.               ], 
  164.               [
  165.                 -78.90582, 
  166.                 43.855466
  167.               ], 
  168.               [
  169.                 -79.639128, 
  170.                 43.855466
  171.               ]
  172.             ]
  173.           ], 
  174.           "type": "Polygon"
  175.         }, 
  176.         "contained_within": [
  177.           {
  178.             "attributes": {}, 
  179.             "bounding_box": {
  180.               "coordinates": [
  181.                 [
  182.                   [
  183.                     -95.155919, 
  184.                     41.676329
  185.                   ], 
  186.                   [
  187.                     -74.339383, 
  188.                     41.676329
  189.                   ], 
  190.                   [
  191.                     -74.339383, 
  192.                     56.852398
  193.                   ], 
  194.                   [
  195.                     -95.155919, 
  196.                     56.852398
  197.                   ]
  198.                 ]
  199.               ], 
  200.               "type": "Polygon"
  201.             }, 
  202.             "country": "Canada", 
  203.             "country_code": "CA", 
  204.             "full_name": "Ontario, Canada", 
  205.             "id": "89b2eb8b2b9847f7", 
  206.             "name": "Ontario", 
  207.             "place_type": "admin", 
  208.             "url": "https://api.twitter.com/1.1/geo/id/89b2eb8b2b9847f7.json"
  209.           }
  210.         ], 
  211.         "country": "Canada", 
  212.         "country_code": "CA", 
  213.         "full_name": "Toronto, Ontario", 
  214.         "id": "8f9664a8ccd89e5c", 
  215.         "name": "Toronto", 
  216.         "place_type": "city", 
  217.         "url": "https://api.twitter.com/1.1/geo/id/8f9664a8ccd89e5c.json"
  218.       }, 
  219.       {
  220.         "attributes": {}, 
  221.         "bounding_box": {
  222.           "coordinates": [
  223.             [
  224.               [
  225.                 -90.867234, 
  226.                 41.898723
  227.               ], 
  228.               [
  229.                 -90.859467, 
  230.                 41.898723
  231.               ], 
  232.               [
  233.                 -90.859467, 
  234.                 41.906811
  235.               ], 
  236.               [
  237.                 -90.867234, 
  238.                 41.906811
  239.               ]
  240.             ]
  241.           ], 
  242.           "type": "Polygon"
  243.         }, 
  244.         "contained_within": [
  245.           {
  246.             "attributes": {}, 
  247.             "bounding_box": {
  248.               "coordinates": [
  249.                 [
  250.                   [
  251.                     -96.639485, 
  252.                     40.375437
  253.                   ], 
  254.                   [
  255.                     -90.140061, 
  256.                     40.375437
  257.                   ], 
  258.                   [
  259.                     -90.140061, 
  260.                     43.501196
  261.                   ], 
  262.                   [
  263.                     -96.639485, 
  264.                     43.501196
  265.                   ]
  266.                 ]
  267.               ], 
  268.               "type": "Polygon"
  269.             }, 
  270.             "country": "United States", 
  271.             "country_code": "US", 
  272.             "full_name": "Iowa, US", 
  273.             "id": "3cd4c18d3615bbc9", 
  274.             "name": "Iowa", 
  275.             "place_type": "admin", 
  276.             "url": "https://api.twitter.com/1.1/geo/id/3cd4c18d3615bbc9.json"
  277.           }
  278.         ], 
  279.         "country": "United States", 
  280.         "country_code": "US", 
  281.         "full_name": "Toronto, IA", 
  282.         "id": "173d6f9c3249b4fd", 
  283.         "name": "Toronto", 
  284.         "place_type": "city", 
  285.         "url": "https://api.twitter.com/1.1/geo/id/173d6f9c3249b4fd.json"
  286.       }, 
  287.       {
  288.         "attributes": {}, 
  289.         "bounding_box": {
  290.           "coordinates": [
  291.             [
  292.               [
  293.                 -95.956873, 
  294.                 37.792724
  295.               ], 
  296.               [
  297.                 -95.941288, 
  298.                 37.792724
  299.               ], 
  300.               [
  301.                 -95.941288, 
  302.                 37.803752
  303.               ], 
  304.               [
  305.                 -95.956873, 
  306.                 37.803752
  307.               ]
  308.             ]
  309.           ], 
  310.           "type": "Polygon"
  311.         }, 
  312.         "contained_within": [
  313.           {
  314.             "attributes": {}, 
  315.             "bounding_box": {
  316.               "coordinates": [
  317.                 [
  318.                   [
  319.                     -102.051769, 
  320.                     36.993016
  321.                   ], 
  322.                   [
  323.                     -94.588387, 
  324.                     36.993016
  325.                   ], 
  326.                   [
  327.                     -94.588387, 
  328.                     40.003166
  329.                   ], 
  330.                   [
  331.                     -102.051769, 
  332.                     40.003166
  333.                   ]
  334.                 ]
  335.               ], 
  336.               "type": "Polygon"
  337.             }, 
  338.             "country": "United States", 
  339.             "country_code": "US", 
  340.             "full_name": "Kansas, US", 
  341.             "id": "27c45d804c777999", 
  342.             "name": "Kansas", 
  343.             "place_type": "admin", 
  344.             "url": "https://api.twitter.com/1.1/geo/id/27c45d804c777999.json"
  345.           }
  346.         ], 
  347.         "country": "United States", 
  348.         "country_code": "US", 
  349.         "full_name": "Toronto, KS", 
  350.         "id": "b90e4628bff4ad82", 
  351.         "name": "Toronto", 
  352.         "place_type": "city", 
  353.         "url": "https://api.twitter.com/1.1/geo/id/b90e4628bff4ad82.json"
  354.       }
  355.     ]
  356.   }
  357. }