menarasolutions / geographer Goto Github PK
View Code? Open in Web Editor NEWPHP library that knows how countries and cities are called in any language
License: MIT License
PHP library that knows how countries and cities are called in any language
License: MIT License
city/KZ.json
{
"code": "9862222",
"long": {
"default": "Кызылорда"
}
I'm having trouble finding a way to lookup a state by iso code, is this possible?
Our team would like to contribute to the translation into Arabic. If you are interested, can you create a "geographer-ar" repository using English translation, so that we can create a PR with Arabic translations?
File not found: /var/www/sites/site.loc/vendor/menarasolutions/geographer-ru/resources/city/TT.json
The data for france regions was valid until 2015 and looked like this:
Elsass (Alsace) | (FR-A)
with a total of 22 regions.
2016 there was a change to three letter codes and only 13 regions like this:
Auvergne-Rhône-Alpes | FR-ARA
[see https://de.wikipedia.org/wiki/ISO_3166-2:FR]
Your collection implementation looks similar to Doctrines
ArrayCollectionwith
ObjectRepository` ontop of it. What do you think about re-using some code from there?
https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/Persistence/ObjectRepository.php
https://github.com/doctrine/collections/blob/master/lib/Doctrine/Common/Collections/Selectable.php
This could lead to some interoperability with other libraries.
Здравствуйте.
У меня будет входной параметр - только название города на английском языке, полное. Как по нему получить объект города? Что-то не нашел такой возможности.
Another mismatch i've found is that Divisible::build static method doing something wrong:
$state = State::build($id); // Instantiate a state directly, based on $id provided (Geonames)
Instead of searching for state with $id, Repositories\File::getCodeFromIndex will search provided $id in indexCountry.json because Divisible::build calls Repository::indexSearch method with static::$parentClass as second argument, which will be equal to Geographer/Country in this case:
public static function build($id, $config = null)
{
$config = $config ?: new DefaultManager();
$meta = $config->getRepository()
->indexSearch($id, static::$parentClass);
$parent = isset($meta['parent']) ? $meta['parent'] : null;
return new static($meta, $parent, $config);
}
I guess static::class should be used there ?
Hello,
About a month ago I wrote that method Country->getCapital does not work.
At branch #40 I got feedback :
I took a look and it turns out this part was never finished properly :) I fixed the method in the code and added a test, but somebody has to make a pull request on geographer-data repo - edit resources/cities/*.json files adding "capital" property to the corresponding entries, eg:
"long": { "default": "Moscow" }, "capital": true,
Now I have the same problem .
I page : https://github.com/MenaraSolutions/geographer/releases/tag/v0.3.10
Fix get capital method
@dusterio dusterio released this 22 days agov0.3.10
In composer.json I modified version of the package and now it has content :
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"cviebrock/eloquent-sluggable": "^8.0",
"drewm/mailchimp-api": "^2.5",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"jenssegers/agent": "^2.6",
"laravel/fortify": "^1.7",
"laravel/framework": "^8.12",
"laravel/sanctum": "^2.8",
"laravel/socialite": "^5.2",
"laravel/tinker": "^2.5",
"laravelcollective/html": "^6.2",
"maatwebsite/excel": "^3.1",
"mailchimp/mailchimp": "^2.0",
"menarasolutions/geographer": "^0.3.10",
"mews/purifier": "^3.3",
"mobiledetect/mobiledetectlib": "^2.8",
"monarobase/country-list": "^3.2",
"spatie/browsershot": "^3.40",
"spatie/emoji": "^2.2",
"spatie/geocoder": "^3.10",
"spatie/laravel-image-optimizer": "^1.6",
"spatie/laravel-permission": "^4.0",
"stidges/laravel-country-flags": "^2.0",
"stripe/stripe-php": "^7.75",
"toin0u/geocoder-laravel": "^4.4",
"wboyz/laravel-enum": "^0.2.1",
"webpatser/laravel-uuid": "^3.0"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel-frontend-presets/tailwindcss": "^4.3",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.2",
"nunomaduro/collision": "^5.0",
"phpunit/phpunit": "^9.3.3"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"files": [
"app/library/helper.php"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
}
I run commands :
php artisan config:cache
php artisan route:cache
php artisan cache:clear
php artisan view:clear
php artisan clear-compiled
composer dump-autoload
and removed “/vendor” and “/composer.lock” and run
composer install and after that example from docs:
$thailand = $earth->getCountries()->findOne(['code' => 'TH']);
$capital = $thailand->getCapital(); // return NULL
I do not if pull request on geographer-data repo was done, but with
"menarasolutions/geographer": "^0.3.10"
I expected this method woul work properly.
How can I make it working?
Thanks!
Hello, is it planned to update the geo database? The current database is very outdated
this code don't return any value
$capital = $thailand->getCapital();
I'm check geographer-data dir, and seems like there not exist any info about capital of countries.
geographer/src/Repositories/File.php
Line 87 in 1f15dde
It took me quite some time to figure out why the libery was failing to load any data on some systems. Please restrict the search replace to the data namespace folder.
Did not see any contribution guidelines in the Readme file but would be very glad to contribute with translations in German and Bulgarian.
My question is if there is something particular, which I and other potential contributors have to be aware of. (would be a good idea to add basic information about the contribution guidelines in the Readme imho)
Good afternoon, when I try to get all the cities on request
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\View;
use MenaraSolutions\Geographer\Earth;
use MenaraSolutions\Geographer\City;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$city = new City();
$city = $city->toArray();
View::share('city', $city);
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
and
<pre>
<?php var_dump($city); ?>
</pre>
Have some error: Undefined index: long
what am I doing wrong?
Describe the bug
Currently if you try to use State::Build() this will fail when the state/division has a single character. e.g. Bangladesh - Dhaka
To Reproduce
Steps to reproduce the behavior:
$country = 'BD';
$state = 'C';
$meta = State::build("{$country}-{$state}")->getMeta();
This will throw:
MenaraSolutions\Geographer\Exceptions\ObjectNotFoundException
Cannot find object with id BD-C
What do you think about that ?
Is documentation obsolete or i am missing something ?
$countries = $earth->getCountries();
$thailand = $countries->findOne(['code' => 'TH']);
Will not work because $earth->getCountries() returns MemberCollection instance, which has no findOne method, only inherited from Divisible has it ( Country, City, State ).
Country list does not exactly match ISO 3166 for at least the African country list. It seems like it's out-of-date:
Missing:
British Indian Ocean Territory
French Southern Territories
Changed:
Current => ISO 3166
Swaziland
=> Eswatini
Mismatch
Current => ISO 3166
Reunion
=> Réunion
United Republic of Tanzania
=> Tanzania, United Republic of
Hello,
We'd like to integrate Geographer in our solution, is there any way you could provide a package for dutch ?
Or describing how we could gather and package data on our own ?
Thank you.
Output:
PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of MenaraSolutions\Geographer\Divisible::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
our team would like to contribute the danish translations. If you are interested, can you create the geographer-da
repository with the english text and we create a PR with the translations?
or are there other ways on how to provide you with the needed information?
I don't see any problems in work. But I have an error in the logs:
Cannot find object with id {"userId":109,"exception":"[object] (MenaraSolutions\Geographer\Exceptions\ObjectNotFoundException(code: 0): Cannot find object with id at /var/www/site.com/main/vendor/menarasolutions/geographer/src/Repositories/File.php:190)
[stacktrace]
#0 /var/www/site.com/main/vendor/menarasolutions/geographer/src/Repositories/File.php(203): MenaraSolutions\Geographer\Repositories\File->getCodeFromIndex()
#1 /var/www/site.com/main/vendor/menarasolutions/geographer/src/Divisible.php(203): MenaraSolutions\Geographer\Repositories\File->indexSearch()
#2 /var/www/site.com/main/app/Models/Geography.php(119): MenaraSolutions\Geographer\Divisible::build()
#3 /var/www/site.com/main/app/Http/Controllers/GeographyController.php(116): App\Models\Geography::cities()
#4 [internal function]: App\Http\Controllers\GeographyController->reqCities()
....
In Laravel 8 I with https://github.com/MenaraSolutions/geographer I need to get capital and its lat/lng
of any country, but I failed to get it with code:
$selectedCountry = $earth->getCountries()->setLocale('en')->findOne(['code' => strtoupper($next_country_key)]);
\Log::info( varDump($selectedCountry, ' -1 $selectedCountry::') );
$capital = $selectedCountry->getCapital();
\Log::info( varDump($capital, ' -1 $capital::') );
$countriesArray[] = [
'label' => $next_country_label,
'value' => $next_country_key,
'geonames_code' => $capital->getGeonamesCode(),
'lat' => $capital->getLatitude(),
'lng' => $capital->getLongitude(),
];
I got error :
Call to a member function getGeonamesCode() on bool
as
$selectedCountry->getCapital()
returned false.
Checking in log content of $selectedCountry var I see:
[2021-04-09 07:26:49] local.INFO: (Object of MenaraSolutions\Geographer\Country) : -1 $selectedCountry:: : Array
(
[ * memberClass] => MenaraSolutions\Geographer\State
[ * exposed] => Array
(
[code] => ids.iso_3166_1.0
[code3] => ids.iso_3166_1.1
[isoCode] => ids.iso_3166_1.0
[numericCode] => ids.iso_3166_1.2
[geonamesCode] => ids.geonames
[fipsCode] => ids.fips
[0] => area
[1] => currency
[phonePrefix] => phone
[2] => mobileFormat
[3] => landlineFormat
[4] => trunkPrefix
[5] => population
[6] => continent
[language] => languages.0
[7] => name
)
[ * meta] => Array
(
[languages] => Array
(
[0] => en
)
[ids] => Array
(
[iso_3166_1] => Array
(
[0] => US
[1] => USA
[2] => 840
)
[fips] => US
[geonames] => 6252001
)
[long] => Array
(
[default] => United States of America
)
[short] => Array
(
[default] => United States
)
[area] => 9629091
[currency] => USD
[phone] => 1
[trunkPrefix] => 1
[landLineFormat] => [2-9]\d{9}
[mobileFormat] => [2-9]\d{9}
[continent] => NA
[population] => 310232863
)
[ * members] =>
[ * manager] => MenaraSolutions\Geographer\Services\DefaultManager Object
(
[translator:protected] => MenaraSolutions\Geographer\Services\TranslationAgency Object
(
[basePath:protected] => /mnt/_work_sdb8/wwwroot/lar/tAdsBack/vendor/menarasolutions/geographer/resources/
[repository:protected] => MenaraSolutions\Geographer\Repositories\File Object
(
[prefix:protected] => /mnt/_work_sdb8/wwwroot/lar/tAdsBack/vendor/menarasolutions/geographer-data/resources
[translationsPrefix:protected] => /mnt/_work_sdb8/wwwroot/lar/tAdsBack/vendor/menarasolutions
[cache:protected] => Array
(
)
)
[form:protected] => default
[inflictsTo:protected] => Array
(
)
[prepositions:protected] => 1
[languages:protected] => Array
(
[ru] => MenaraSolutions\Geographer\Services\Poliglottas\Russian
[en] => MenaraSolutions\Geographer\Services\Poliglottas\English
[es] => MenaraSolutions\Geographer\Services\Poliglottas\Spanish
[it] => MenaraSolutions\Geographer\Services\Poliglottas\Italian
[fr] => MenaraSolutions\Geographer\Services\Poliglottas\French
[zh] => MenaraSolutions\Geographer\Services\Poliglottas\Mandarin
[uk] => MenaraSolutions\Geographer\Services\Poliglottas\Ukrainian
[de] => MenaraSolutions\Geographer\Services\Poliglottas\German
[nl] => MenaraSolutions\Geographer\Services\Poliglottas\Dutch
)
[translators:protected] => Array
(
)
)
[repository:protected] => MenaraSolutions\Geographer\Repositories\File Object
(
[prefix:protected] => /mnt/_work_sdb8/wwwroot/lar/tAdsBack/vendor/menarasolutions/geographer-data/resources
[translationsPrefix:protected] => /mnt/_work_sdb8/wwwroot/lar/tAdsBack/vendor/menarasolutions
[cache:protected] => Array
(
)
)
[language:protected] => en
[form:protected] =>
[standard:protected] => iso
[brief:protected] => 1
[prepositions:protected] => 1
[path:protected] => /mnt/_work_sdb8/wwwroot/lar/tAdsBack/vendor/menarasolutions/geographer/resources/
)
[ MenaraSolutions\Geographer\Divisible parent] =>
[ * parentCode] => SOL-III
[ * standard] =>
)
Does this package have no info on USA capital or something wrong in my code?
I followed docs on github page...
"menarasolutions/geographer": "^0.3.9",
"menarasolutions/geographer-laravel": "^0.2.1",
"laravel/framework": "^8.12",
Thanks!
Hello!
I read issue #18 about all cities. So could you please make additional db with all-all cities? It is VERY need.
Я что то пропустил или таймзон у городов действительно нет????????
Return type of MenaraSolutions\Geographer\Divisible::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .../vendor/menarasolutions/geographer/src/Traits/ExposesFields.php on line 46
Return type of MenaraSolutions\Geographer\Collections\Traits\ImplementsArray::unserialize($serialized) should either be compatible with ArrayObject::unserialize(string $data): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in .../vendor/menarasolutions/geographer/src/Collections/Traits/ImplementsArray.php on line 74
HI I am trying to add the package in lumen but when i try to register the package it give me error that class Integrations is not available can you please check that
Hi, maybe I didn't investigated, but is there an ability to directly get cities within a country?
The problem is that some small countries doesn't have states, so I couldn't get cities for this country.
Thanks!
Здравствуйте.
Подскажите пожалуйста, есть ли возможность использовать кастомную memberCollection?
Или может вы можете интегрировать функцию slice в дефолт?
public function slice($offset, $length = null)
{
return new static($this->manager, array_slice($this->_divisions, $offset, $length, true));
}
очень полезна для постраничного вывода
The data does provides ids. iso_3166_2 but in the city class, both geonames and the code is the same value.
https://github.com/MenaraSolutions/geographer/blob/master/src/City.php#L25
Hi,
It seems you lost most of the Gabon cities: Akieni, Bakoumba, Bitam, Bongoville, Booue, Cocobeach, Fougamou, Franceville, Gamba, Kango, Koula-Moutou, Lambarene, Lembamba, Leconi, Makokou, Mandji, Mayumba, Mbigou, Medouneu, Mekambo, Mimongo, Minvoul, Mitzic, Moabj, Moanda, Mouila, Ndende, N'Djole, N'Toum, Okondja, Omboue, Ovan, Oyem, Pana, Tchibanga.
There are only two cities in the geographer-data pkg for Gabon.
Hi, I have a problem that not all cities from The Netherlands are included in the NL.json file (geographer-data/resources/NL.json). I have a dating site and i want that users from all cities to be able to register on my site, because now people from certain cities cannot register and this is a big problem for me. Can you generate a NL.json file with all cities from The Netherlands and mail it to me? or find another solution?
Best Regards,
Media4now
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.