\Hazaar
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.

Tags

Since

2.3.44

Author

Jamie Carl

Summary
Methods Properties Constants
$db
No constants
Properties
$db
$db
The internal B-Tree database adapter
Static
$sources
$sources
The publicly available GeoData database data sources.
Static
$version
$version
The current GeoData database format version.

Changing this triggers a re-initialisation of the internal database.

Methods
__construct()
__construct()
__initialise()
__initialise() : boolean
Initialises the internal B-Tree database with all available data

Tags

Throws

\Exception

Returns

boolean
__list()
__list($db, $field = 'name') : array
Obtains a list of all countries indexed by code

Parameters

$db\Hazaar\Btree

No description

$fieldmixed

No description

Returns

array
cities()
cities($country_code, $state_code) : array
Retrieve a list of cities for the requested country and state

Using a two character ISO country code and the state code this method will return an array of cities in that state.

Parameters

$country_codestring

Two character ISO country code.

$state_codestring

State code.

Returns

array

An array of city names.

countries()
countries() : array
Retrieve a list of countries

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.

Returns

array
country_area()
country_area($country_code) : int
Quick access method to retrieve country area in square kilometers.

Parameters

$country_codestring

Two character ISO country code.

Returns

int
country_capital()
country_capital($country_code) : string
Quick access method to retrieve country capital name.

Parameters

$country_codestring

Two character ISO country code.

Returns

string
country_capital_timezone()
country_capital_timezone($country_code) : string
Quick access method to retrieve country capital timezone.

Parameters

$country_codestring

Two character ISO country code.

Returns

string
country_code()
country_code($name) : string
Quick access method to find a country code using the name of the country.

Parameters

$namestring

The full name of the country to get the ISO code for.

Returns

string
country_continent()
country_continent($country_code) : array
Quick access method to retrieve country continent info.

Parameters

$country_codestring

Two character ISO country code.

Returns

array
country_hosts()
country_hosts($country_code) : int
Quick access method to retrieve country estimated internet hosts.

Parameters

$country_codestring

Two character ISO country code.

Returns

int
country_info()
country_info($code) : array
Retrieve information about a country by it's ISO code.

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

$codestring

The two character ISO country code to get information for.

Returns

array

An array of available country information.

country_languages()
country_languages($country_code) : array
Quick access method to retrieve country language info.

Parameters

$country_codestring

Two character ISO country code.

Returns

array
country_name()
country_name($country_code) : string
Quick access method to retrieve a country name.

Parameters

$country_codestring

A two character ISO country code.

Returns

string
country_phone_code()
country_phone_code($country_code) : int
Quick access method to retrieve country phone dialling code.

Parameters

$country_codestring

Two character ISO country code.

Returns

int
country_users()
country_users($country_code) : int
Quick access method to retrieve country estimated internet users.

Parameters

$country_codestring

Two character ISO country code.

Returns

int
states()
states($country_code) : array
Retrieve a list of states for a country

Using a two character ISO country code, this method will return a list of states for that country.

Parameters

$country_codestring

Two character ISO country code

Returns

array

An array of states with their state code as the key and full name as the value.