countries-states-cities-database
收藏Place
数据集概述
Place 是一个 Elixir 库和数据集,包含全球国家、州和城市的名称、ISO 3166 代码、货币等信息。数据源基于 countries-states-cities-database 项目,并定期更新。
数据结构示例
elixir iex> Place.get_country(country_code: "US") %Place.Country{ capital: "Washington", csc_id: 233, csc_region_id: "2", csc_subregion_id: "6", currency: "USD", currency_name: "United States dollar", currency_symbol: "$", emoji: "🇺🇸", emojiU: "U+1F1FA U+1F1F8", iso2: "US", iso3: "USA", latitude: "38.00000000", longitude: "-97.00000000", name: "United States", nationality: "American", native: "United States", numeric_code: "840", phone_code: "1", ... # 更多字段 }
功能示例
-
获取所有国家: elixir iex> Place.get_countries() |> Enum.count() 250
-
获取某个国家的所有州: elixir iex> Place.get_states(country_code: "US") |> Enum.count() 66 # 额外 16 个是非州属的美国领土,可通过
type字段识别。 -
获取某个州的所有城市: elixir iex> Place.get_cities(country_code: "US", state_code: "CA") |> Enum.count() 1124
-
获取特定国家: elixir iex> Place.get_country(country_code: "US") %Place.Country{ ..., name: "United States", ... }
-
获取特定州: elixir iex> Place.get_state(country_code: "US", state_code: "CA") %Place.State{ ..., name: "California", ... }
-
获取特定城市: elixir iex> Place.get_city(country_code: "US", state_code: "CA", city_name: "Los Angeles") %Place.City{ ..., name: "Los Angeles", ... }
数据库加载
Place 提供了一个压缩的数据库文件,包含 countries-states-cities-database 数据集。可以通过 Place.load_csc_db!() 显式加载数据库。
许可证
Place 使用 MIT 许可证,数据库文件使用 ODbL-1.0 许可证。




