GeoData
GeoData
The GeoData class for accessing geographic information on countries.
This method allows access to useful country information such as codes, names, continents, states, cities and various other data.
Data is obtained via the publicly available GeoLite2 databases provided by MaxMind.
See the MaxMind GeoLite2 Pages for more information.
Currently, IP information is not stored and only country/state/city level data is searchable.
The first time the \Hazaar\GeoData class is used it needs to download some files and construct an internal B-Tree database. This requires HTTP access to the internet and depending on the speed of the connection can take some time (usually around 10-15 seconds). Once the B-Tree database is constructed then data access speeds are extremely fast.
Constants
int
public const int = nullProperties
sources
The publicly available GeoData database data sources.
private array $sources = array (
'url' => 'https://api.hazaar.io/databases/geodata.zip',
'md5' => 'https://api.hazaar.io/databases/geodata.zip.md5',
)db
public BTree $dbdbFile
private string $dbFile = 'geodata.db'Methods
__construct
public __construct(?string $dbFile): voidParameters
| Parameter | Type | Description |
|---|---|---|
$dbFile | string |
__list
Obtains a list of all countries indexed by code.
private __list(BTree $db, ?string $field): voidParameters
| Parameter | Type | Description |
|---|---|---|
$db | BTree | |
$field | string |
fetchDBFile
Fetch the GeoData database file from the remote API server and extract it.
public fetchDBFile(?string $dbFileName = 'geodata.db'): FileParameters
| Parameter | Type | Description |
|---|---|---|
$dbFileName | string |
countries
Retrieve a list of countries.
public countries(): voidThis method will return an associative array containing a list of all countries organised by their two character ISO code. The ISO code is the key and the country name is the value.
countryInfo
Retrieve information about a country by it's ISO code.
public countryInfo(string $code): voidThis method will return an array that contains:
- id := The GeoNamesID
- code := Two character ISO country code
- name := Country name
- continent := Continent info containing the continent ISO code and name.
- phone_code := Two digit telephone dialing code (E164)
- languages := Array of languages used in this country
- capital := Name of the capital city
- capital_timezone := The timezone in the capital city
- area := Physical area in KM/2
- hosts := Estimated number of active internet hosts
- users := Estimated number of active internet users
Parameters
| Parameter | Type | Description |
|---|---|---|
$code | string | the two character ISO country code to get information for |
countryInfoAll
Retrieve information about all countries.
public countryInfoAll(): voidThis method will return an array of all countries with their ISO code as the key and an array of country information as the value.
states
Retrieve a list of states for a country.
public states(string $countryCode): voidUsing a two character ISO country code, this method will return a list of states for that country.
Parameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | Two character ISO country code |
cities
Retrieve a list of cities for the requested country and state.
public cities(string $countryCode, string $stateCode): voidUsing a two character ISO country code and the state code this method will return an array of cities in that state.
Parameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
$stateCode | string | state code |
countryName
Quick access method to retrieve a country name.
public countryName(string $countryCode): stringParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | a two character ISO country code |
countryCode
Quick access method to find a country code using the name of the country.
public countryCode(string $name): ?stringParameters
| Parameter | Type | Description |
|---|---|---|
$name | string | the full name of the country to get the ISO code for |
countryContinent
Quick access method to retrieve country continent info.
public countryContinent(string $countryCode): voidParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
countryLanguages
Quick access method to retrieve country language info.
public countryLanguages(string $countryCode): voidParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
countryPhoneCode
Quick access method to retrieve country phone dialling code.
public countryPhoneCode(string $countryCode): intParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
countryCapital
Quick access method to retrieve country capital name.
public countryCapital(string $countryCode): stringParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
countryCapitalTimezone
Quick access method to retrieve country capital timezone.
public countryCapitalTimezone(string $countryCode): stringParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
countryArea
Quick access method to retrieve country area in square kilometers.
public countryArea(string $countryCode): intParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
countryHosts
Quick access method to retrieve country estimated internet hosts.
public countryHosts(string $countryCode): intParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
countryUsers
Quick access method to retrieve country estimated internet users.
public countryUsers(string $countryCode): intParameters
| Parameter | Type | Description |
|---|---|---|
$countryCode | string | two character ISO country code |
Generated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000