PHPackages                             izisoft/geographer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. izisoft/geographer

ActiveLibrary[Localization &amp; i18n](/categories/localization)

izisoft/geographer
==================

A PHP library that knows how any country, state or city is called in any language

v0.3.9(5y ago)020MITPHPPHP &gt;=5.5.0

Since Apr 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/izisoft/geographer)[ Packagist](https://packagist.org/packages/izisoft/geographer)[ Docs](https://github.com/MenaraSolutions/geographer)[ RSS](/packages/izisoft-geographer/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (7)Versions (17)Used By (0)

Geographer
==========

[](#geographer)

[![Build Status](https://camo.githubusercontent.com/44c42ad41bf127a9089adf8609554093580ce9d7d2a7542e9977848c57127674/68747470733a2f2f7472617669732d63692e6f72672f4d656e617261536f6c7574696f6e732f67656f677261706865722e737667)](https://travis-ci.org/MenaraSolutions/geographer)[![Code Climate](https://camo.githubusercontent.com/52cbf248a4c2ff9ca775bee775be284e88c9cbf49c6b32a4681d7d643803210d/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4d656e617261536f6c7574696f6e732f67656f677261706865722f6261646765732f6770612e737667)](https://codeclimate.com/github/MenaraSolutions/geographer/badges)[![Test Coverage](https://camo.githubusercontent.com/955699f2238d162b98154767ba3fda69d269ca85cb45bd3c0312d8c3ced8f6ac/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f4d656e617261536f6c7574696f6e732f67656f677261706865722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/MenaraSolutions/geographer/badges)[![Total Downloads](https://camo.githubusercontent.com/ab5d286fdfc46836dec5e154cd1a2c5f181ce7558b837f1a8797827f9de418fd/68747470733a2f2f706f7365722e707567782e6f72672f6d656e617261736f6c7574696f6e732f67656f677261706865722f646f776e6c6f616473)](https://packagist.org/packages/menarasolutions/geographer)[![Latest Stable Version](https://camo.githubusercontent.com/8709591a1a6937a6a9363fe718cc4cf0ff47b4f856b784bc7408b99b8311e2de/68747470733a2f2f706f7365722e707567782e6f72672f4d656e617261536f6c7574696f6e732f67656f677261706865722f762f737461626c652e737667)](https://packagist.org/packages/MenaraSolutions/geographer)[![Latest Unstable Version](https://camo.githubusercontent.com/0ad7242ad82dd6238c82a377fc9bbb9975b6ed14e230de6b85b5d06630fcbb2a/68747470733a2f2f706f7365722e707567782e6f72672f4d656e617261536f6c7574696f6e732f67656f677261706865722f762f756e737461626c652e737667)](https://packagist.org/packages/MenaraSolutions/geographer)[![License](https://camo.githubusercontent.com/8bcc397ef6f13c876e998b35f79c3b61c5fbaa8a30f61f7c312f35c94eaac096/68747470733a2f2f706f7365722e707567782e6f72672f4d656e617261536f6c7574696f6e732f67656f677261706865722f6c6963656e73652e737667)](https://packagist.org/packages/MenaraSolutions/geographer)

Geographer is a PHP library that knows how any country, state or city is called in any language. [Documentation on the official website](https://geographer.su/documentation/php/)

Includes integrations with: Laravel 5, Lumen 5

[![Geographer](https://camo.githubusercontent.com/adada61c7756bf859800df3f08ebc48984e3a3186f6fd8ce8af3672ae4653fd4/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f67656f677261706865725f636f766572322e6a7067)](https://camo.githubusercontent.com/adada61c7756bf859800df3f08ebc48984e3a3186f6fd8ce8af3672ae4653fd4/68747470733a2f2f7777772e6d7973656e6b6f2e636f6d2f696d616765732f67656f677261706865725f636f766572322e6a7067)

Dependencies
------------

[](#dependencies)

- PHP &gt;= 5.5

Installation via Composer
-------------------------

[](#installation-via-composer)

To install simply run:

```
$ composer require menarasolutions/geographer

```

Or add it to `composer.json` manually:

```
{
    "require": {
        "menarasolutions/geographer": "~0.3"
    }
}
```

This, main package is shipped with English language so add extra dependencies for your other languages, eg.:

```
$ composer require menarasolutions/geographer-es

```

Usage
-----

[](#usage)

```
use MenaraSolutions\Geographer\Earth;
use MenaraSolutions\Geographer\Country;

// Default entry point is our beautiful planet
$earth = new Earth();

// Give me a list of all countries please
$earth->getCountries()->toArray();

// Oh, but please try to use short versions, eg. USA instead of United States of America
$earth->getCountries()->useShortNames()->toArray();

// Now please give me all states of Thailand
$thailand = $earth->getCountries()->findOne(['code' => 'TH']); // You can call find on collection
$thailand = $earth->findOne(['code' => 'TH']); // Or right away on division
$thailand = $earth->findOneByCode('TH'); // Alternative shorter syntax
$thailand = Country::build('TH'); // You can build a country object directly, too
$thailand->getStates()->toArray();

// Oh, but I want them in Russian
$thailand->getStates()->setLocale('ru')->toArray();

// Oh, but I want them inflicted to 'in' form (eg. 'in Spain')
$thailand->getStates()->setLocale('ru')->inflict('in')->toArray();

// Or if you prefer constants for the sake of IDE auto-complete
$thailand->getStates()->setLocale(TranslationAgency::LANG_RUSSIAN)->inflict(TranslationAgency::FORM_IN)->toArray();

// What's the capital and do you have a geonames ID for that? Or maybe latitude and longitude?
$capital = $thailand->getCapital();
$capital->getGeonamesCode();
$capital->getLatitude();
$capital->getLongitude();
```

Collections
-----------

[](#collections)

Arrays of administrative divisions (countries, states or cities) are returned as collections – a modern way of implementing arrays. Some of the available methods are:

```
$states->sortBy('name'); // States will be sorted by name
$states->setLocale('ru')->sortBy('name'); // States will be sorted by Russian translations/names
$states->find(['code' => 472039]); // Find 1+ divisions that match specified parameters
$states->findOne(['code' => 472039]); // Return the first match only
$states->findOneByCode(472039); // Convenience magic method
$states->toArray(); // Return a flat array of states
$states->pluck('name'); // Return a flat array of state names
```

Common methods on division objects
----------------------------------

[](#common-methods-on-division-objects)

All objects can do the following:

```
$object->toArray(); // Return a flat array with all data
$object->parent(); // Return a parent (city returns a state, state returns a country)
$object->getCode(); // Get default unique ID
$object->getShortName(); // Get short (colloquial) name of the object
$object->getLongName(); // Get longer name
$object->getCodes(); // Get a plain array of all available unique codes
```

You can access information in a number of ways, do whatever you are comfortable with:

```
$object->getName(); // Get object's name (inflicted and shortened when necessary)
$object->name; // Same effect
$object['name']; // Same effect
$object->toArray()['name']; // Same effect again
```

Subdivision standards
---------------------

[](#subdivision-standards)

By default, we will use ISO-3166-1 country and ISO 3166-2 state classification. Therefore, countries or states that don't have ISO codes are not visible by default. Please note that FIPS 10-4 is a deprecated (abandoned) standard. It's better not to rely on it – new states and/or countries won't appear in FIPS.

You can change subdivision standard with `setStandard` method:

```
$country->setStandard(DefaultManager::STANDARD_ISO); // ISO subdivisions
$country->setStandard(DefaultManager::STANDARD_FIPS); // FIPS 10-4 subdivisions
$country->setStandard(DefaultManager::STANDARD_GEONAMES); // Geonames subdivisions
```

This will affect `getStates()` and `getCountries()` output.

Earth API
---------

[](#earth-api)

Earth object got the following convenience methods:

```
$earth->getAfrica(); // Get a collection of African countries
$earth->getEurope(); // Get a collection of European countries
$earth->getNorthAmerica(); // You can guess
$earth->getSouthAmerica();
$earth->getAsia();
$earth->getOceania();

$earth->getCountries(); // A collection of all countries
$earth->withoutMicro(); // Only countries that have population of at least 100,000
```

By default, we will use ISO 3166-1 country classification.

Country API
-----------

[](#country-api)

Country objects got the following encapsulated data:

```
$country->getCode(); //ISO 3166-1 alpha-2 (2 character) code
$country->getCode3(); // ISO 3166-1 alpha-3
$country->getNumericCode(); // ISO 3166-1 numeric code
$country->getGeonamesCode(); // Geonames ID
$country->getFipsCode(); // FIPS code
$country->getArea(); // Area in square kilometers
$country->getCurrencyCode(); // National currency, eg. USD
$country->getPhonePrefix(); // Phone code, eg. 7 for Russia
$country->getPopulation(); // Population
$country->getLanguage(); // Country's first official language

$country->getStates(); // A collection of all states
Country::build('TH'); // Build a country object based on ISO code
```

Geonames, ISO 3166-1 alpha-2, alpha-3 and numeric codes are four viable options to reference country in your data store.

State API
---------

[](#state-api)

At this moment Geographer only keeps cities with population above 50,000 for the sake of performance.

```
$state->getCode(); // Get default code (currently Geonames)
$state->getIsoCode(); // Get ISO 3166-2 code
$state->getFipsCode(); // Get FIPS code
$state->getGeonamesCode(); // Get Geonames code

$state->getCities(); // A collection of all cities
$state = State::build($id); // Instantiate a state directly, based on $id provided (Geonames or ISO)
```

Geonames, ISO 3166-2 and FIPS are all unique codes so all three can be used to reference states in your data store.

City API
--------

[](#city-api)

```
$city->getCode(); // This is always a Geonames code for now
$city = City::build($id); // Instantiate a city directly, based on $id provided (Geonames)
$city->getLatitude(); // City's latitude
$city->getLongitude(); // City's longitude
$city->getPopulation(); // Population
```

Geonames ID is currently the only viable option to reference a city in your data store.

Integrations with frameworks
----------------------------

[](#integrations-with-frameworks)

[Official Laravel package](https://github.com/MenaraSolutions/geographer-laravel)

Current coverage: subdivisions
------------------------------

[](#current-coverage-subdivisions)

TypeISO 3166FIPSGeonamesGENCCountries100%Coming soon100%TBCStates100%Coming soon100%TBCSubdivision data is kept in a separate repo - [geographer-data](https://github.com/MenaraSolutions/geographer-data) so that it may be reused by different language SDKs.

Current coverage: translations
------------------------------

[](#current-coverage-translations)

By default Geographer assumes that you use Packagist (Composer) to install language packages, therefore we will expect them in vendor/ folder. There is no need to manually turn on an extra language, but if you attempt to use a non-existing language – expect an exception.

LanguageCountriesStatesCitiesPackageEnglish100%100%100%[geographer-data](https://github.com/MenaraSolutions/geographer-data)Russian100%100%63%[geographer-ru](https://github.com/MenaraSolutions/geographer-ru)Ukrainian✓✓✓[geographer-uk](https://github.com/MenaraSolutions/geographer-uk)Spanish✓✓✓[geographer-es](https://github.com/MenaraSolutions/geographer-es)Italian✓✓✓[geographer-it](https://github.com/MenaraSolutions/geographer-it)French✓✓✓[geographer-fr](https://github.com/MenaraSolutions/geographer-fr)German✓✓✓[geographer-de](https://github.com/MenaraSolutions/geographer-de)Chinese Mandarin✓✓✓[geographer-zh](https://github.com/MenaraSolutions/geographer-zh)English texts are included in the data package and are used as default metadata.

Vision
------

[](#vision)

Our main principles and goals are:

1. Be lightweight and independent – so that this package can be pulled anywhere alone
2. Coverage – Geographer should cover all countries and languages
3. Be extensible – developers should be able to override and extend easily

Performance
-----------

[](#performance)

While not a number one priority at this stage, we will try maintain reasonable CPU and memory performance. Some benchmarks:

**Inflating a city based on its Id**

Time: 6 ms, memory: 81056 bytes

Video tutorials
---------------

[](#video-tutorials)

I've just started a educational YouTube channel that will cover top IT trends in software development and DevOps: [config.sys](https://www.youtube.com/channel/UCIvUJ1iVRjJP_xL0CD7cMpg)

Todo
----

[](#todo)

1. Add a basic spatial index
2. Add some unit tests (in addition to existing integration tests)
3. Add coverage information for language packages

Projects using Geographer
-------------------------

[](#projects-using-geographer)

- [GrammarCI – Typo Detection for developers](https://www.grammarci.com/)

Tell us about yours!

Contribution
------------

[](#contribution)

Read our [Contribution guide](https://github.com/MenaraSolutions/geographer/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

The MIT License (MIT) Copyright (c) 2016 Denis Mysenko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~100 days

Recently: every ~185 days

Total

16

Last Release

2189d ago

PHP version history (2 changes)v0.1PHP &gt;=5.5.0

v0.1.1PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2edf0df855a366ea51f96bd910a60c87320c973460ccc273a7e448ae32eedb65?d=identicon)[zinzinx8](/maintainers/zinzinx8)

---

Top Contributors

[![dusterio](https://avatars.githubusercontent.com/u/11039918?v=4)](https://github.com/dusterio "dusterio (232 commits)")[![zinzinx8](https://avatars.githubusercontent.com/u/13455399?v=4)](https://github.com/zinzinx8 "zinzinx8 (5 commits)")[![Xmk](https://avatars.githubusercontent.com/u/1087368?v=4)](https://github.com/Xmk "Xmk (2 commits)")[![enniel](https://avatars.githubusercontent.com/u/19760944?v=4)](https://github.com/enniel "enniel (2 commits)")[![GinoPane](https://avatars.githubusercontent.com/u/3897579?v=4)](https://github.com/GinoPane "GinoPane (2 commits)")[![michaelantipenko](https://avatars.githubusercontent.com/u/18105393?v=4)](https://github.com/michaelantipenko "michaelantipenko (2 commits)")[![timacdonald](https://avatars.githubusercontent.com/u/24803032?v=4)](https://github.com/timacdonald "timacdonald (2 commits)")[![zquintana](https://avatars.githubusercontent.com/u/130444?v=4)](https://github.com/zquintana "zquintana (1 commits)")[![jamosaur](https://avatars.githubusercontent.com/u/4105611?v=4)](https://github.com/jamosaur "jamosaur (1 commits)")[![vsychov](https://avatars.githubusercontent.com/u/2186303?v=4)](https://github.com/vsychov "vsychov (1 commits)")[![willishq](https://avatars.githubusercontent.com/u/1564903?v=4)](https://github.com/willishq "willishq (1 commits)")[![Big-Shark](https://avatars.githubusercontent.com/u/646054?v=4)](https://github.com/Big-Shark "Big-Shark (1 commits)")

---

Tags

localizationgeolocationgeogeonames

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/izisoft-geographer/health.svg)

```
[![Health](https://phpackages.com/badges/izisoft-geographer/health.svg)](https://phpackages.com/packages/izisoft-geographer)
```

###  Alternatives

[menarasolutions/geographer

A PHP library that knows how any country, state or city is called in any language

765733.1k4](/packages/menarasolutions-geographer)[symfony/intl

Provides access to the localization data of the ICU library

2.6k199.8M1.1k](/packages/symfony-intl)[commerceguys/addressing

Addressing library powered by CLDR and Google's address data.

95430.2M43](/packages/commerceguys-addressing)[gettext/languages

gettext languages with plural rules

7530.3M11](/packages/gettext-languages)[menarasolutions/geographer-data

Basic data package for Geographer - countries and their subdivisions

26754.6k2](/packages/menarasolutions-geographer-data)[devrabiul/laravel-geo-genius

Laravel GeoGenius — A powerful, intelligent toolkit for geo-location, timezone, and locale-based features in Laravel applications.

1757.6k](/packages/devrabiul-laravel-geo-genius)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
