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.
- Full name:
\Hazaar\GeoData
Constants
Constant | Visibility | Type | Value |
---|---|---|---|
VERSION | public | 2 |
Properties
sources
The publicly available GeoData database data sources.
private static array<string,string> $sources
- This property is static.
db
The internal B-Tree database adapter.
private static ?\Hazaar\File\BTree $db
- This property is static.
Methods
__construct
public __construct(bool $re_intialise = false): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$re_intialise | bool |
__initialise
Initialises the internal B-Tree database with all available data.
private __initialise(): bool
Throws:
__list
Obtains a list of all countries indexed by code.
private __list(\Hazaar\File\BTree $db, ?string $field = null): array<string,string>
Parameters:
Parameter | Type | Description |
---|---|---|
$db | \Hazaar\File\BTree | |
$field | ?string |
countries
Retrieve a list of countries.
public countries(): array<string,string>
This 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): array<string,mixed>
This 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 |
Return Value:
an array of available country information
countryInfoAll
Retrieve information about all countries.
public countryInfoAll(): array
This method will return an array of all countries with their ISO code as the key and an array of country information as the value.
Return Value:
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 $country_code): array<string,string>
Using a two character ISO country code, this method will return a list of states for that country.
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | Two character ISO country code |
Return Value:
an array of states with their state code as the key and full name as the value
cities
Retrieve a list of cities for the requested country and state.
public cities(string $country_code, string $state_code): string[]
Using 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 |
---|---|---|
$country_code | string | two character ISO country code |
$state_code | string | state code |
Return Value:
an array of city names
countryName
Quick access method to retrieve a country name.
public countryName(string $country_code): string
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | 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): ?string
Parameters:
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 $country_code): array<string,string>
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryLanguages
Quick access method to retrieve country language info.
public countryLanguages(string $country_code): string[]
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryPhoneCode
Quick access method to retrieve country phone dialling code.
public countryPhoneCode(string $country_code): int
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryCapital
Quick access method to retrieve country capital name.
public countryCapital(string $country_code): string
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryCapitalTimezone
Quick access method to retrieve country capital timezone.
public countryCapitalTimezone(string $country_code): string
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryArea
Quick access method to retrieve country area in square kilometers.
public countryArea(string $country_code): int
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryHosts
Quick access method to retrieve country estimated internet hosts.
public countryHosts(string $country_code): int
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryUsers
Quick access method to retrieve country estimated internet users.
public countryUsers(string $country_code): int
Parameters:
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
Automatically generated on 2024-11-14