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
const int =
Properties
sources
The publicly available GeoData database data sources.
private array $sources
db
public BTree $db
Methods
__construct
public __construct({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$re_intialise | bool |
__initialise
Initialises the internal B-Tree database with all available data.
private __initialise({Array})
__list
Obtains a list of all countries indexed by code.
private __list({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$db | BTree | |
$field | string |
countries
Retrieve a list of countries.
public countries({Array})
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({Array})
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 |
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.
states
Retrieve a list of states for a country.
public states({Array})
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 |
cities
Retrieve a list of cities for the requested country and state.
public cities({Array})
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 |
countryName
Quick access method to retrieve a country name.
public countryName({Array})
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({Array})
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({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryLanguages
Quick access method to retrieve country language info.
public countryLanguages({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryPhoneCode
Quick access method to retrieve country phone dialling code.
public countryPhoneCode({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryCapital
Quick access method to retrieve country capital name.
public countryCapital({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryCapitalTimezone
Quick access method to retrieve country capital timezone.
public countryCapitalTimezone({Array})
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({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryHosts
Quick access method to retrieve country estimated internet hosts.
public countryHosts({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
countryUsers
Quick access method to retrieve country estimated internet users.
public countryUsers({Array})
Parameters
Parameter | Type | Description |
---|---|---|
$country_code | string | two character ISO country code |
Generated by Hazaar API Doc Generator