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.

Summary
MethodsPropertiesConstants
No constants
Properties
Static
$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($re_intialise = false)
__initialise()
__initialise() : boolean
Initialises the internal B-Tree database with all available data
__list()
__list($db, $field = null) : array
Obtains a list of all countries indexed by code
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.

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.

country_area()
country_area($country_code) : int
Quick access method to retrieve country area in square kilometers.
country_capital()
country_capital($country_code) : string
Quick access method to retrieve country capital name.
country_capital_timezone()
country_capital_timezone($country_code) : string
Quick access method to retrieve country capital timezone.
country_code()
country_code($name) : string
Quick access method to find a country code using the name of the country.
country_continent()
country_continent($country_code) : array
Quick access method to retrieve country continent info.
country_currency()
country_currency($country_code) : mixed
Return the currency used by a country by it's country code.
country_currency_info()
country_currency_info($country_code) : mixed
Return the currency used by a country by it's country code.
country_hosts()
country_hosts($country_code) : int
Quick access method to retrieve country estimated internet hosts.
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
country_info_all()
country_info_all()
country_languages()
country_languages($country_code) : array
Quick access method to retrieve country language info.
country_name()
country_name($country_code) : string
Quick access method to retrieve a country name.
country_phone_code()
country_phone_code($country_code) : int
Quick access method to retrieve country phone dialling code.
country_users()
country_users($country_code) : int
Quick access method to retrieve country estimated internet users.
parseCSV()
parseCSV($file, $key_name)
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.