Skip to main content
Helpful?

Cities

Import​

import { cities } from "country-cities";

Get all cities​

const allCities = cities.all();

console.log(allCities)

The result will be:

[
{
countryCode: "AU",
latitude: "-31.12756000",
longitude: "150.90711000",
name: "Hillvue",
stateCode: "NSW",
},
{
countryCode: "AU",
latitude: "-33.91878000",
longitude: "150.86314000",
name: "Hinchinbrook",
stateCode: "NSW",
},
...
]

Get Cities by Country​

const auCities = cities.getByCountry("AU");

console.log(auCities)

The result will be:

[
{
countryCode: "AU",
latitude: "-31.12756000",
longitude: "150.90711000",
name: "Hillvue",
stateCode: "NSW",
},
{
countryCode: "AU",
latitude: "-33.91878000",
longitude: "150.86314000",
name: "Hinchinbrook",
stateCode: "NSW",
},
...
]

Get Cities by State and Country​

const nswCities = cities.getByState("NSW", "AU");

console.log(nswCities)
Important: The country code should be entered second parameter

The result will be:

[
{
countryCode: "AU",
latitude: "-31.12756000",
longitude: "150.90711000",
name: "Hillvue",
stateCode: "NSW",
},
{
countryCode: "AU",
latitude: "-33.91878000",
longitude: "150.86314000",
name: "Hinchinbrook",
stateCode: "NSW",
},
...
]
Helpful?