> ## Documentation Index
> Fetch the complete documentation index at: https://docs.countrystatecity.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Nearby Search

> Find countries, states, and cities near a coordinate, ranked by straight-line distance

Find countries, states, or cities near a `lat`/`lng` coordinate. Results are ordered from nearest to farthest.

<Warning>
  **This is not address search.** It does not:

  * Find a street address
  * Check whether a point is inside a country or state border
  * Return country/state map shapes
  * Calculate travel time or road distance

  It measures straight-line distance to the stored coordinate for a city, state, or country.
</Warning>

<Note>**Availability:** Supporter, Professional, and Business plans. Other plans receive `403`. [Compare plans](https://countrystatecity.in/pricing?source=playground\&campaign=nearby_search), or see **Trying it without a paid plan** below.</Note>

## Response

Returns an array, nearest-first. Each item carries the standard fields for the entity at your plan's data-access level, plus:

<Note>
  State and city results always include `country_name` (and, for cities, `state_name`), regardless of your plan's data-access level — useful for display without a second lookup. This differs from [Autocomplete](/api/endpoints/get-search-autocomplete), which instead always includes `country_code`/`state_code` on city results; nearby search doesn't force those two.
</Note>

<RequestExample>
  ```bash cURL (cities near Mumbai) theme={null}
  curl -X GET 'https://api.countrystatecity.in/v1/search/nearby?lat=19.0760&lng=72.8777&radius=25&kind=settlement' \
    -H 'X-CSCAPI-KEY: YOUR_API_KEY'
  ```

  ```bash cURL (states within 300km, minimum population) theme={null}
  curl -X GET 'https://api.countrystatecity.in/v1/search/nearby?lat=19.0760&lng=72.8777&type=state&radius=300&min_population=1000000' \
    -H 'X-CSCAPI-KEY: YOUR_API_KEY'
  ```

  ```bash cURL (cities within a specific state) theme={null}
  curl -X GET 'https://api.countrystatecity.in/v1/search/nearby?lat=19.0760&lng=72.8777&country=IN&state=MH&limit=5' \
    -H 'X-CSCAPI-KEY: YOUR_API_KEY'
  ```

  ```javascript JavaScript theme={null}
  const params = new URLSearchParams({ lat: '19.0760', lng: '72.8777', radius: '25' });
  const response = await fetch(
    `https://api.countrystatecity.in/v1/search/nearby?${params}`,
    { headers: { 'X-CSCAPI-KEY': 'YOUR_API_KEY' } }
  );

  const results = await response.json();
  results.forEach((r) => console.log(`${r.name} — ${r.distance_km} km`));
  ```

  ```python Python theme={null}
  import requests

  response = requests.get(
    'https://api.countrystatecity.in/v1/search/nearby',
    params={'lat': 19.0760, 'lng': 72.8777, 'radius': 25},
    headers={'X-CSCAPI-KEY': 'YOUR_API_KEY'}
  )

  for result in response.json():
      print(f"{result['name']} — {result['distance_km']} km")
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - Cities near Mumbai (Supporter, Professional, Business) theme={null}
  [
    {
      "id": 57606,
      "name": "Mumbai",
      "kind": "settlement",
      "state_id": 4008,
      "state_code": "MH",
      "country_id": 101,
      "country_code": "IN",
      "latitude": "19.07600000",
      "longitude": "72.87770000",
      "population": 12442373,
      "timezone": "Asia/Kolkata",
      "wikiDataId": "Q1156",
      "country_name": "India",
      "state_name": "Maharashtra",
      "distance_km": 0
    },
    {
      "id": 57612,
      "name": "Thane",
      "kind": "settlement",
      "state_id": 4008,
      "state_code": "MH",
      "country_id": 101,
      "country_code": "IN",
      "latitude": "19.21830000",
      "longitude": "72.97810000",
      "population": 1841488,
      "timezone": "Asia/Kolkata",
      "wikiDataId": "Q210421",
      "country_name": "India",
      "state_name": "Maharashtra",
      "distance_km": 17.36
    }
  ]
  ```

  ```json 400 - Latitude out of range theme={null}
  {
    "status": "error",
    "message": "Invalid query parameters: lat: lat must be between -90 and 90"
  }
  ```

  ```json 400 - state without country theme={null}
  {
    "status": "error",
    "message": "Invalid query parameters: state: country is required when filtering by state"
  }
  ```

  ```json 403 - Feature Restricted theme={null}
  {
    "status": "error",
    "message": "This feature is not available on your current plan.",
    "details": {
      "feature": "nearbySearch",
      "currentTier": "starter",
      "requiredTier": "supporter",
      "upgradeUrl": "https://app.countrystatecity.in/pricing"
    }
  }
  ```
</ResponseExample>

## Trying it without a paid plan

The interactive API documentation uses a shared **Playground** plan. It is only for trying the endpoint in the docs. For your own app, [choose a Supporter plan or higher](https://countrystatecity.in/pricing?source=playground\&campaign=nearby_search).

## Related Endpoints

* [Autocomplete](/api/endpoints/get-search-autocomplete) — type-ahead search by name, not location
* [Fuzzy Search](/api/endpoints/fuzzy-search) — typo-tolerant search by name
* [Get Cities by Country](/api/endpoints/get-cities-by-country) — list cities, filterable by `?q=`

The [CLI](/api/sdks/cli) also provides a `csc nearby` command for this endpoint.


## OpenAPI

````yaml GET /search/nearby
openapi: 3.0.3
info:
  title: Country State City API
  description: >-
    Geographic data API providing countries, states, cities, timezones,
    currencies, and phone dial codes with tiered access levels.


    ## Authentication

    All endpoints require an API key passed via the `X-CSCAPI-KEY` header. Get
    your free key at [app.countrystatecity.in](https://app.countrystatecity.in).


    ## Pricing & Limits

    The fields returned, endpoints available, and request quotas depend on your
    plan. See current tiers and limits at:


    **[countrystatecity.in/pricing](https://countrystatecity.in/pricing)**


    ## Data Access Levels

    Each plan includes a data access level that controls which fields are
    returned:


    - **Basic** — Core fields: id, name, iso2, iso3, phonecode, capital,
    currency, coordinates, region, timezones, emoji

    - **Coordinates** — Basic + extended metadata (population, tld, nationality,
    currency details, postal codes, etc.)

    - **Full** — All fields including translations (18+ languages) and
    wikiDataId


    Fields restricted to higher tiers are marked in each schema below.


    ## Feature Gating

    Some endpoints require a minimum tier. Restricted endpoints return `403`
    with an `upgradeUrl` when accessed on a lower plan. Check the [pricing
    page](https://countrystatecity.in/pricing) for current feature availability.


    ## Rate Limiting

    Requests exceeding your daily or monthly quota receive a `429` response with
    your current limit, period, tier, and an upgrade URL.


    ## Caching

    Cacheable geographic responses include `Cache-Control`, `ETag`, and
    `X-Cache` (HIT/MISS) headers; send `If-None-Match` on them to receive `304
    Not Modified`. Phone number parsing is never cached (`Cache-Control:
    no-store`, no `ETag`); see each endpoint for exceptions.


    ## Usage Headers

    All `/v1/*` responses include usage and plan headers:

    - `X-CSC-Plan` — your current tier

    - `X-CSC-Daily-Used` / `X-CSC-Daily-Limit` — today's usage vs limit

    - `X-CSC-Monthly-Used` / `X-CSC-Monthly-Limit` — this month's usage vs limit


    Use these to monitor consumption without a separate API call.
  contact:
    name: Darshan Gada (dr5hn)
    email: gadadarshan@gmail.com
    url: https://countrystatecity.in
  license:
    name: Creative Commons Attribution 4.0
    url: https://creativecommons.org/licenses/by/4.0/
  version: 2.4.1
servers:
  - url: https://api.countrystatecity.in/v1
    description: Production API
security: []
tags:
  - name: Countries
    description: Country data — 250+ countries with metadata, coordinates, and translations
  - name: States
    description: State/province/region data — 5,000+ subdivisions
  - name: Cities
    description: City data — 150,000+ cities worldwide
  - name: Postcodes
    description: >-
      Postcode and ZIP code lookup and search. Informational data, not address
      verification.
  - name: Regions
    description: Geographic regions and subregions — continental groupings of countries
  - name: Timezones
    description: >-
      IANA timezone lookup by country, state, or city — includes UTC offset and
      DST status
  - name: Currencies
    description: ISO 4217 currency data — list all currencies or look up by country
  - name: Phone
    description: >-
      International dial codes — list, lookup by country, and E.164 phone number
      parsing
  - name: ISO
    description: >-
      ISO 3166 code lookup and conversion — country (alpha-2/3/numeric) and
      state (ISO 3166-2)
  - name: Search
    description: Typo-tolerant fuzzy search across cities, states, and countries
  - name: Changes
    description: >-
      Data change feed — track additions, removals, and updates to place records
      over time. **Professional and Business plans only.**
  - name: Meta
    description: Information about the dataset release currently served
paths:
  /search/nearby:
    get:
      tags:
        - Search
      summary: Nearby search
      description: >-
        Find the nearest cities, states, or countries to a coordinate pair.
        Results are sorted by `distance_km`, nearest first.


        This is **not** street-address search, map-boundary containment, road
        distance, or travel time. It measures straight-line distance to known
        place points.


        Example: `?lat=19.076&lng=72.878&type=city&kind=settlement` finds
        settlements near Mumbai.


        **Availability:** Supporter+ plans for production use. Other plans can
        try it in the public playground. [Compare
        plans](https://countrystatecity.in/pricing?source=api_playground&campaign=nearby_search).
      operationId: nearbySearch
      parameters:
        - name: lat
          in: query
          description: Latitude of the search origin
          required: true
          schema:
            type: number
            minimum: -90
            maximum: 90
            example: 19.076
        - name: lng
          in: query
          description: Longitude of the search origin
          required: true
          schema:
            type: number
            minimum: -180
            maximum: 180
            example: 72.878
        - name: type
          in: query
          description: Entity type to search
          required: false
          schema:
            type: string
            enum:
              - city
              - state
              - country
            default: city
            example: city
        - name: kind
          in: query
          description: City classification filter. Valid only when `type=city`.
          required: false
          schema:
            type: string
            enum:
              - settlement
              - administrative
              - section
              - unknown
            example: settlement
        - name: country
          in: query
          description: ISO 3166-1 alpha-2 country code. Invalid when `type=country`.
          required: false
          schema:
            type: string
            minLength: 2
            maxLength: 2
            pattern: ^[A-Za-z]{2}$
            example: IN
        - name: state
          in: query
          description: >-
            State or province code for a city search. Requires `country` and is
            valid only when `type=city`.
          required: false
          schema:
            type: string
            minLength: 1
            maxLength: 20
            example: MH
        - name: min_population
          in: query
          description: Minimum population a result must have
          required: false
          schema:
            type: integer
            format: int64
            minimum: 0
            maximum: 9007199254740991
            example: 100000
        - name: radius
          in: query
          description: Search radius in kilometers (1–500)
          required: false
          schema:
            type: number
            minimum: 1
            maximum: 500
            default: 25
            example: 25
        - name: limit
          in: query
          description: Maximum number of results (1–100)
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
            example: 20
        - name: locale
          in: query
          description: >-
            Adds `localized_name` and `matched_locale` using exact locale → base
            language → native name → English name fallback. The English `name`,
            stable `id`, and distance stay unchanged. **Supporter+ plans only.**
          required: false
          schema:
            type: string
            minLength: 2
            maxLength: 7
            pattern: ^[a-zA-Z]{2}(-[a-zA-Z]{2,4})?$
            example: ja
        - name: include_translations
          in: query
          description: >-
            When `true`, includes the full translation JSON string. **Supporter+
            plans only.**
          required: false
          schema:
            type: boolean
            default: false
            example: true
      responses:
        '200':
          description: Matching results sorted from nearest to farthest
          headers:
            Cache-Control:
              $ref: '#/components/headers/CacheControl'
            ETag:
              $ref: '#/components/headers/ETag'
            X-Cache:
              $ref: '#/components/headers/XCache'
            X-CSC-Plan:
              $ref: '#/components/headers/XCSCPlan'
            X-CSC-Daily-Used:
              $ref: '#/components/headers/XCSCDailyUsed'
            X-CSC-Daily-Limit:
              $ref: '#/components/headers/XCSCDailyLimit'
            X-CSC-Monthly-Used:
              $ref: '#/components/headers/XCSCMonthlyUsed'
            X-CSC-Monthly-Limit:
              $ref: '#/components/headers/XCSCMonthlyLimit'
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/NearbyResult'
        '400':
          description: >-
            Missing or invalid query parameter, or a country, state, or kind
            filter used with an invalid entity type
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatusError'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: Feature not available on your current plan. Requires Supporter+.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FeatureError'
              example:
                status: error
                message: This feature is not available on your current plan.
                details:
                  feature: nearbySearch
                  currentTier: starter
                  requiredTier: supporter
                  upgradeUrl: https://countrystatecity.in/pricing
        '429':
          $ref: '#/components/responses/RateLimited'
      security:
        - ApiKeyAuth: []
components:
  headers:
    CacheControl:
      description: Cache directive
      schema:
        type: string
        example: public, max-age=3600
    ETag:
      description: Entity tag for conditional requests (use with `If-None-Match`)
      schema:
        type: string
        example: '"a3f2b8c1d4e5f6a7b8c9d0e1f2a3b4c5"'
    XCache:
      description: Whether the response was served from cache
      schema:
        type: string
        enum:
          - HIT
          - MISS
        example: HIT
    XCSCPlan:
      description: Your current pricing tier
      schema:
        type: string
        enum:
          - community
          - starter
          - supporter
          - professional
          - business
          - legacy
          - custom
        example: supporter
    XCSCDailyUsed:
      description: Number of requests used today
      schema:
        type: integer
        example: 42
    XCSCDailyLimit:
      description: Your daily request limit (or 'unlimited' for custom plans)
      schema:
        type: string
        example: '1000'
    XCSCMonthlyUsed:
      description: Number of requests used this month
      schema:
        type: integer
        example: 850
    XCSCMonthlyLimit:
      description: Your monthly request limit (or 'unlimited' for custom plans)
      schema:
        type: string
        example: '30000'
  schemas:
    NearbyResult:
      type: object
      description: >-
        One nearby result. Normal fields depend on the selected entity type and
        API plan.
      properties:
        type:
          type: string
          nullable: true
          description: >-
            Raw source type for a state or city. This is not the
            country/state/city query type. Available on the coordinates tier and
            above.
          example: city
        kind:
          type: string
          enum:
            - settlement
            - administrative
            - section
            - unknown
          description: Derived city classification. Present on city results for every plan.
          example: settlement
        id:
          type: integer
          format: int64
          description: Entity ID
          example: 57606
        name:
          type: string
          description: English place name
          example: Mumbai
        translations:
          type: string
          nullable: true
          description: >-
            JSON string of translations. **Supporter+ plans only, and only when
            `include_translations=true` is passed.**
        localized_name:
          type: string
          nullable: true
          description: >-
            Localized display name selected by `locale`. The English `name`
            remains unchanged. **Supporter+ plans only.**
          example: ムンバイ
        matched_locale:
          type: string
          nullable: true
          description: >-
            Translation or fallback used for `localized_name`: the exact locale,
            base language, `native`, or `en`. **Supporter+ plans only.**
          example: ja
        iso2:
          type: string
          nullable: true
          description: >-
            Country ISO2 code for countries or state ISO code for states. Not
            present on city results.
          example: IN
        iso3:
          type: string
          nullable: true
          description: Country ISO3 code. Present only on country results.
          example: IND
        state_code:
          type: string
          nullable: true
          description: >-
            Parent state code for city results. Available on the coordinates
            tier and above.
          example: MH
        country_code:
          type: string
          nullable: true
          description: >-
            Parent country code. Always present on state results; available on
            city results on the coordinates tier and above.
          example: IN
        country_name:
          type: string
          description: >-
            Parent country name. Present on state and city results for every
            plan.
          example: India
        state_name:
          type: string
          nullable: true
          description: >-
            Parent state name. Present on city results for every plan; null when
            there is no parent state.
          example: Maharashtra
        distance_km:
          type: number
          description: Straight-line distance from the search origin in kilometers
          example: 3.42
      required:
        - id
        - name
        - distance_km
    StatusError:
      type: object
      description: Error envelope used by the postcode and meta endpoints.
      properties:
        status:
          type: string
          example: error
        message:
          type: string
        details:
          type: object
          nullable: true
          properties:
            reason:
              type: string
              description: >-
                Machine-readable reason. Check this instead of parsing
                `message`.
          additionalProperties: true
      required:
        - status
        - message
    FeatureError:
      type: object
      properties:
        status:
          type: string
          enum:
            - error
        message:
          type: string
          example: This feature is not available on your current plan.
        details:
          type: object
          properties:
            feature:
              type: string
              description: The feature flag that was denied
              example: bulkStates
            currentTier:
              type: string
              example: community
            requiredTier:
              type: string
              nullable: true
              description: >-
                Lowest plan that unlocks the feature; null when it cannot be
                determined
              example: starter
            upgradeUrl:
              type: string
              format: uri
              example: https://countrystatecity.in/pricing
          required:
            - feature
            - currentTier
            - requiredTier
            - upgradeUrl
      required:
        - status
        - message
        - details
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
      required:
        - error
    RateLimitError:
      type: object
      properties:
        error:
          type: string
          example: >-
            Daily usage limit exceeded. Please try again tomorrow or contact
            support for higher limits.
        limit:
          type: integer
          description: Your plan's limit for the exceeded period
          example: 100
        period:
          type: string
          enum:
            - daily
            - monthly
          example: daily
        tier:
          type: string
          description: Your current tier
          example: community
        upgradeUrl:
          type: string
          description: URL to upgrade your plan
          example: https://countrystatecity.in/pricing
      required:
        - error
  responses:
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: Unauthorized. You shouldn't be here.
    RateLimited:
      description: Daily or monthly usage limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/RateLimitError'
          example:
            error: >-
              Daily usage limit exceeded. Please try again tomorrow or contact
              support for higher limits.
            limit: 100
            period: daily
            tier: community
            upgradeUrl: https://countrystatecity.in/pricing
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: >-
        API key for authentication. Get your free key at
        [app.countrystatecity.in](https://app.countrystatecity.in).
      name: X-CSCAPI-KEY
      in: header

````

## Related topics

- [Localized Place Names](/api/localization.md)
- [Changelog](/changelog.md)
- [SQL Server Installation](/database/installation/sql-server.md)
- [MongoDB Installation](/database/installation/mongodb.md)
- [Fuzzy Search](/api/endpoints/fuzzy-search.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.