Places & time zones
Place search
GET/v1/places/search
Search as you type for a city, town or village: coordinates, time zone, district, state and country.
- Covers more than 5.5 lakh places in India and 2.3 lakh worldwide.
- Finds old names (Bombay, Allahabad), Indian scripts and other spellings.
- Narrow the search after a comma:
Rampur, Uttar Pradeshorrampur, up. - Keep the
idof the place the user picked and send it asplace_idto any calculation. matchis exact, starts_with, contains (a later word), other_name (an older or other name) or similar (spelled differently).- Always let the user pick; never take a similar match for them.
- Call it from your server, so your key stays there.
- Wait about 200 ms after the last keystroke. Each search is one call.
- The same fields can be sent as a JSON body with POST.
- Village coordinates are approximate. An error of 2 km moves the ascendant by about 0.02 degrees.
- Place data: GeoNames, CC BY 4.0, adapted.
Request
Send these in the query string.
| Field | Type | Description |
|---|---|---|
| q | stringrequired | The name, or its first letters. Add a district, state or country after a comma |
| country | string | Two-letter country code, for example IN, to search one country only |
| limit | integer | Places to return, 1-50 (default 10) |
| datetime | string | Local date and time; adds the UTC offset in force then to every place |
Example
curl -X GET "https://api.bestastroapi.in/v1/places/search?q=gorakh&country=IN&limit=3" \
-H "x-api-key: $BESTASTRO_KEY"Response
[]is a list.{key}is a key that varies.
| Field | Type | Meaning |
|---|---|---|
| query | string | The text you sent |
| count | integer | Places returned |
| places | Place[] | Best match first. Can be empty |
Objects used above
Place A city, town or village.
| Field | Type | Meaning |
|---|---|---|
| id | integer | Stable id. Send it as place_id to any calculation |
| name | string | Name |
| district | string or null | District or county |
| state | string or null | State or province |
| country | string | Country |
| country_code | string | Two-letter country code |
| label | string | Ready to show: name, district for smaller places, state, country |
| lat | numberdegrees | Latitude |
| lon | numberdegrees | Longitude |
| tz | string | IANA time zone |
| population | integer or null | Population. Null when not known, which is usual for villages |
| match | string | Why it is listed. Only in place search optionalexact | starts_with | contains | other_name | similar |
| utc_offset | string | UTC offset at datetime. Only in place search with datetime optional |
Raw sample
200 application/json
{
"count": 3,
"places": [
{
"country": "India",
"country_code": "IN",
"district": "Gorakhpur",
"id": 1270927,
"label": "Gorakhpur, Uttar Pradesh, India",
"lat": 26.76628,
"lon": 83.36889,
"match": "starts_with",
"name": "Gorakhpur",
"population": 674246,
"state": "Uttar Pradesh",
"tz": "Asia/Kolkata"
},
{
"country": "India",
"country_code": "IN",
"district": "Fatehabad",
"id": 1270926,
"label": "Gorakhpur, Fatehabad, Haryana, India",
"lat": 29.44768,
"lon": 75.67206,
"match": "starts_with",
"name": "Gorakhpur",
"population": 13068,
"state": "Haryana",
"tz": "Asia/Kolkata"
},
{
"country": "India",
"country_code": "IN",
"district": "Betul",
"id": 1270932,
"label": "Gorakhar, Betul, Madhya Pradesh, India",
"lat": 21.78483,
"lon": 77.90199,
"match": "starts_with",
"name": "Gorakhar",
"population": null,
"state": "Madhya Pradesh",
"tz": "Asia/Kolkata"
}
],
"query": "gorakh"
}Real output for the example request above.
Errors use one format. See error codes. Also in openapi.json.