Skip to content

geo

facts about countries and cities, and distances and directions between places

Permissions: network, cache

Built-in facts about the world’s countries and cities, and distances and directions between places.

The functions here look up countries by name or by their two- or three-letter ISO code, and cities by name. Short names and missing accents are fine. When several cities share a name the biggest one wins, so add a country or state after a comma to pick another, like "Portland, US".

Where a function takes a place, give a city or country name (a country means its capital), or a map with lat and lon.

A place’s name also works with to as a currency, so $100 to "Vietnam" gives dong, and as a time zone.

City and country data comes from GeoNames (geonames.org, CC-BY 4.0) and covers capitals and cities of over 500,000 people.

Tags: geometry

  • country facts about a country, found by name or ISO code
  • city facts about a city
  • countries every country, as a table with the same columns as country gives
  • cities every city, as a table with the same columns as city gives, biggest first
  • great_circle the distance between two places along the Earth’s surface, the shortest route, which is roughly the one planes fly
  • bearing the compass direction to set off in from one place to reach another, in degrees clockwise from north (90 is east)
  • nearest the city closest to a latitude and longitude, out of those zil knows
  • zipcode look up a postal code online
1
# countries by name or ISO code
2
country("JPN").name"Japan"
3
# short names and missing accents work
4
[city("NYC").name, city("Sao Paulo").name]["New York City", "São Paulo"]
5
# add a country or state to pick another
6
city("Hyderabad, PK").country"Pakistan"
7
# a place can also be a map with lat and lon
8
great_circle("Paris", {lat: 0, lon: 0})5436.93 km
Example outputCtrl+Enter to run
country(name: str) -> map

facts about a country, found by name or ISO code

Its name, two- and three-letter codes, capital, currency, time zones, phone calling code, population, area, continent, flag, languages and neighbours

1
country("Japan"){name: "Japan", code: "JP", code3: "JPN", capital: "Tokyo", currency: "JPY", zones: ["Asia/Tokyo"], calling: "+81", population: 126529100, area: 377835 km^2, continent: "Asia", flag: "🇯🇵", languages: ["ja"], neighbours: []}
2
country("UK").currency"GBP"
Example outputCtrl+Enter to run

See also city, countries

city(name: str) -> map

facts about a city

Its name, country, state or region (admin), population, latitude and longitude, and time zone

1
city("Tokyo"){name: "Tokyo", country: "Japan", admin: "Tokyo", population: 9733276, lat: 35.6895, lon: 139.692, zone: "Asia/Tokyo"}
2
city("Seattle").zone"America/Los_Angeles"
Example outputCtrl+Enter to run

See also country, cities, nearest

countries() -> table

every country, as a table with the same columns as country gives

1
countries().len252
2
countries().filter(|c| c.continent == "Oceania").map(|c| c.name).take(3)["American Samoa", "Australia", "Cook Islands"]
Example outputCtrl+Enter to run

See also country, cities

cities() -> table

every city, as a table with the same columns as city gives, biggest first

1
cities()[0].name"Shanghai"
Example outputCtrl+Enter to run

See also city, countries

great_circle(from: str|map, to: str|map) -> quantity

the distance between two places along the Earth’s surface, the shortest route, which is roughly the one planes fly

1
great_circle("Tokyo", "Paris")9712.52 km
2
great_circle("NYC", "LA") to mi2445.56 mi
Example outputCtrl+Enter to run

See also bearing, nearest

bearing(from: str|map, to: str|map) -> quantity

the compass direction to set off in from one place to reach another, in degrees clockwise from north (90 is east)

1
bearing("NYC", "London")51.2117 deg
Example outputCtrl+Enter to run

See also great_circle

nearest(lat: num, lon: num) -> map

the city closest to a latitude and longitude, out of those zil knows

1
nearest(48.9, 2.3).name"Paris"
Example outputCtrl+Enter to run

See also city, great_circle

zipcode(code: str, country: str = “US”) -> map

look up a postal code online

Codes looked up before work offline. Gives its place name, state, country, latitude and longitude. The result works as a place for great_circle

1
zipcode("90210").place
2
zipcode("10115", "Germany")
3
great_circle(zipcode("10001"), zipcode("94103")) to mi
Example outputCtrl+Enter to run

See also city

1
# currency of a country
2
country("Vietnam").currency"VND"
3
# time in any city
4
date("2026-12-25 18:30") to "Seattle"2026-12-25 16:30:00 -08:00
5
# flying distance from New York to London
6
great_circle("New York", "London") to mi3461.18 mi
7
# which compass direction Mecca is from London
8
bearing("London", "Mecca")118.988 deg
9
# sunset in a city
10
sunset("Oslo", date(2026, 6, 21))2026-06-21 15:43:43 -05:00
11
# how many countries use the euro
12
countries().filter(|c| c.currency == "EUR").len36
13
# biggest cities in Japan
14
cities().filter(|c| c.country == "Japan").map(|c| c.name).take(3)["Tokyo", "Yokohama", "Osaka"]
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.