T

TechIdea

Ecosystem

Free Cities API

The Cities API offers comprehensive data on millions of cities, towns, and municipalities across the globe. It is highly optimized for search, autocomplete, and geospatial queries. Developers can use this API to populate dropdown menus, resolve IP locations to city names, or calculate distances between urban centers.

GEThttps://techidea.online/api/v1/cities

What is a REST API?

An API (Application Programming Interface) allows two software programs to communicate. A REST API uses standard HTTP requests like GET (to read data), POST (to create data), PUT (to update), and DELETE (to remove).

When you send a request to our https://techidea.online/api/v1/cities endpoint, our server responds with a JSON (JavaScript Object Notation) array containing data. You can then display this data in your frontend React, Next.js, or mobile applications.

Developer Features

Pagination

Use ?limit=10&page=2

Filtering

Use ?search=keyword

Sorting

Use ?sort=id&order=asc

Code Examples

import { useState } from 'react';

function CitySearch() {
  const [results, setResults] = useState([]);

  const handleSearch = async (e) => {
    const res = await fetch(`https://api.example.com/v1/cities?search=${e.target.value}`);
    const data = await res.json();
    setResults(data.data);
  };

  return (
    <div>
      <input type="text" onChange={handleSearch} placeholder="Search city..." />
      <ul>
        {results.map(city => <li key={city.id}>{city.name}</li>)}
      </ul>
    </div>
  );
}

Sample Response

200 OK - application/json
{
  "data": [
    {
      "id": 2643743,
      "name": "London",
      "country": "United Kingdom",
      "countryCode": "GB",
      "population": 8982000,
      "latitude": 51.5085,
      "longitude": -0.1257,
      "timezone": "Europe/London"
    }
  ],
  "metadata": {
    "totalCount": 1
  }
}

What to Build (Project Ideas)

Smart Location Autocomplete

Build a high-performance location input field for registration forms or search filters.

Implementation Steps

  • 1. Create a text input that triggers debounced API requests on change.
  • 2. Call the API using the search query parameter and filter by country if necessary.
  • 3. Display the results in a dropdown list showing city name and administrative region.
  • 4. Upon selection, save the city coordinates for further geospatial processing.

Distance Calculator

A tool that calculates the great-circle distance between two cities.

Implementation Steps

  • 1. Implement two autocomplete inputs using the Cities API to select origin and destination.
  • 2. Extract the latitude and longitude from the selected cities.
  • 3. Use the Haversine formula to compute the distance between the two points.
  • 4. Display the distance in kilometers and miles, along with a simple map visualization.

Frequently Asked Questions

Does the API return small towns and villages?

The database includes settlements with a population of 1000 or more. Very small villages might not be included.

Can I search cities within a specific radius?

Yes, the API supports geospatial queries where you can specify a latitude, longitude, and radius in kilometers.

Continue Learning

Use these resources to deepen your understanding of API integration and build portfolio-worthy projects.

Growth Newsletter

Get practical AI tools, SEO tips, and growth guides weekly.

Join creators, students, and businesses scaling with TechIdea.