A Laravel (php) package to interface with the geo-location services at geonames.org.

Related tags

Laravel Geonames
Overview

geonames v7.x

Latest Stable Version Total Downloads License GitHub issues GitHub forks GitHub stars Travis (.org)

A Laravel (php) package to interface with the geo-location services at geonames.org.

Major Version Jump

I jumped several major versions to catch up with Larvel's major version number. Makes things a little clearer.

Notes

There is still a lot that needs to be done to make this package "complete". I've gotten it to a point where I can use it for my next project. As time allows, I will improve the documentation and testing that comes with this package. Thanks for understanding.

Installation

composer require michaeldrennen/geonames

And then add geonames provider to providers array in app.php config file:

MichaelDrennen\Geonames\GeonamesServiceProvider::class,

After that, Run migrate command:

php artisan migrate

Want to install all of the geonames records for the US, Canada, and Mexico as well as pull in the feature codes definitions file in English?

php artisan geonames:install --country=US --country=CA --country=MX --language=en

Want to just install everything in the geonames database?

php artisan geonames:install

Maintenance

Now that you have the geonames database up and running on your system, you need to keep it up-to-date.

I have an update script that you need to schedule in Laravel to run every day.

Some info on how to schedule Laravel artisan commands:

https://laravel.com/docs/5.6/scheduling#scheduling-artisan-commands

You can read this notice at: http://download.geonames.org/export/dump/

The "last modified" timestamp is in Central European Time.

It looks like geonames updates their data around 3AM CET.

So if you schedule your system to run the geonames:update artisan command after 4AM CET, you should be good to go.

I like to keep my servers running on GMT. Keeps things consistent.

(Central European Time is 1 hour ahead of Greenwich Mean Time)

Assuming your servers are running on GMT, your update command would look like:

$schedule->command('geonames:update')->dailyAt('3:00');

The update artisan command will handle the updates and deletes to the geonames table.

Gotchas

Are you getting something like: 1071 Specified key was too long

@see https://laravel-news.com/laravel-5-4-key-too-long-error

Add this to your AppServiceProvider.php file:

Schema::defaultStringLength(191);

A quick word on indexes

This library contains a bunch of migrations that contain a bunch of indexes. Now not everyone will need all of the indexes.

So when you install this library, run the migrations and delete the indexes that you don't need.

Also, Laravel doesn't let you specify a key length for indexes on varchar columns. There are two indexes suffering from this limit. Instead of creating indexes on those columns the "Laravel way", I send a raw/manual query to create the indexes with the proper lengths.

Comments
  • Problems with backslash (Windows, DIRECTORY_SEPARATOR)

    Problems with backslash (Windows, DIRECTORY_SEPARATOR)

    It seems like this problem is still here: https://github.com/michaeldrennen/Geonames/issues/18 PHP constant DIRECTORY_SEPARATOR on Windows system is backslash: "\" On MySQL query running it make a troubles:

    # php.exe artisan geonames:install --country=EN --language=en
    .............................................................
    Inserting via LOAD DATA INFILE: D:\OpenServer\domains\project\storage\geonames\iso-languagecodes.txt
    SQLSTATE[HY000]: General error: 7890 Can't find file 'D:OpenServerdomainsprojectstoragegeonamesiso-languagecodes'.
    
    PDO::exec("LOAD DATA LOCAL INFILE 'D:\OpenServer\domains\project\storage\geonames\iso-languagecodes.txt'
        INTO TABLE geonames_iso_language_codes_working IGNORE 1 LINES
            (   iso_639_3,
                iso_639_2,
                iso_639_1,
                language_name,
                @created_at,
                @updated_at)
        SET created_at=NOW(),updated_at=null")
    
    opened by sngrl 6
  • Importing data problem

    Importing data problem

    When i'm running

    php artisan geonames:install --country=ru --language=ru

    i get error :

    SQLSTATE[22003]: Numeric value out of range: 1264 Out of range value for column 'isHistoric' at row 1 (SQL: insert into geonames_alternate_names_working (alternateNameId, geonameid, isolanguage, alternate_name, isPreferredName, isShortName, isColloquial, isHistoric, updated_at, created_at) values (9528154, 472757, en, Volgograd, 1, 0, 0, 1961, 2018-05-04 09:19:35, 2018-05-04 09:19:35))
    /var/www/zdravproduct-app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664

    Looks like isHistoric tinyint but trying insert value '1961'

    opened by michaelslobodskih 4
  • Issue #43 fix: Problems with backslash (Windows, DIRECTORY_SEPARATOR)

    Issue #43 fix: Problems with backslash (Windows, DIRECTORY_SEPARATOR)

    Change DIRECTORY_SEPARATOR to environment variable with default value.

    See issue #43: Problems with backslash (Windows, DIRECTORY_SEPARATOR)

    It's important to merge pull request to LocalFile package at first: https://github.com/michaeldrennen/LocalFile/pull/5

    opened by sngrl 3
  • Laravel 7 not supporting

    Laravel 7 not supporting

    Hello Michael and thank you for your contribution! Will be any updates about latest Laravel?

    Log file: Problem 1 - Conclusion: remove laravel/framework v7.9.2 - Conclusion: don't install laravel/framework v7.9.2 - michaeldrennen/geonames v3.0.0 requires illuminate/database ^6.8 -> satisfiable by laravel/framework[6.x-dev], illuminate/database[6.x-dev, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.10, v6.18.11, v6.18.2, v6.18.3, v6.18.4, v6.18.5, v6.18.6, v6.18.7, v6.18.8, v6.18.9, v6.8.0]. - michaeldrennen/geonames v3.0.1 requires illuminate/database ^6.8 -> satisfiable by laravel/framework[6.x-dev], illuminate/database[6.x-dev, v6.10.0, v6.11.0, v6.12.0, v6.13.0, v6.13.1, v6.14.0, v6.15.0, v6.15.1, v6.16.0, v6.17.0, v6.17.1, v6.18.0, v6.18.1, v6.18.10, v6.18.11, v6.18.2, v6.18.3, v6.18.4, v6.18.5, v6.18.6, v6.18.7, v6.18.8, v6.18.9, v6.8.0]. - Can only install one of: laravel/framework[6.x-dev, v7.9.2]. - don't install illuminate/database 6.x-dev|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.10.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.11.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.12.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.13.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.13.1|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.14.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.15.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.15.1|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.16.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.17.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.17.1|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.0|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.1|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.10|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.11|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.2|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.3|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.4|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.5|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.6|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.7|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.8|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.18.9|don't install laravel/framework v7.9.2 - don't install illuminate/database v6.8.0|don't install laravel/framework v7.9.2 - Installation request for laravel/framework (locked at v7.9.2, required as ^7.0) -> satisfiable by laravel/framework[v7.9.2]. - Installation request for michaeldrennen/geonames ^3.0 -> satisfiable by michaeldrennen/geonames[v3.0.0, v3.0.1].

    enhancement 
    opened by skywalkerAlex 3
  • "1071 Specified key was too long" will never be resolved with Schema::defaultStringLength(191)

    The problem

    I'm testing ^2.0 version of this package and found to install exactly the version 2.0.2 after requiring it through Composer.

    When I ran the php artisan migration I'm getting the following error:

    Illuminate\Database\QueryException :
    SQLSTATE[42000]:
    Syntax error or access violation:
    1071 Specified key was too long; max key length is 1000 bytes
    (SQL: alter table `geonames_alternate_names` add index `geonames_alternate_names_alternate_name_index`(`alternate_name`))
    

    Digging through the migration code I found that it was thrown into 2017_02_11_145951_create_geonames_alternate_names_table.php line 70:

    $table->index( 'alternate_name' );
    

    If we comment this line the Artisan's migration command will run without any errors. But I went even deeper into the problem:

    Some explanation

    The error says that the max key length is 1000 bytes and the above highlighted line is trying to create an index key for the alternate_name column. This column is defined in the same migration file at line 37 as a VARCHAR with length 400 (!!!). When we define the length of a column explicitly how it is done at this line, the code Schema::defaultStringLength(191) may be inserted into boot method of AppServiceProvider.php and will just be ignored (at least by this line) resulting on the same error because the basic Laravel collation is utf8mb4 which uses 4 bytes to each char on a VARCHAR column and 400 * 4 = 1600 bytes which is much greater than the maximum size of 1000 bytes to a key (like specified by the error).

    What I recommend to solve it

    I understand that creating an index to alternate_name column is useful to make filters when querying geonames_alternate_names table. But this table isn't important to everyone using this package (also depending on how and why we are using it there may have more tables which will not be important though). Also, this column stores something like a CSV data, so it could be parsed and stored in another way to avoid creating a VARCHAR(400).

    Also, why not let us publish the migrations and commands and change them as we need?

    Don't misunderstand me, the package is awesome, it just need a bit of improvement

    bug 
    opened by thbighead 3
  • Error when running route:cache

    Error when running route:cache

    ./artisan route:cache gives that result :

    Route cache cleared!
    
    In Route.php line 917:
    Unable to prepare route [geonames/examples/vue/element/autocomplete] for serialization. Uses Closure```
    opened by Nuranto 3
  • "violation: 1071 Specified key was too long"

    Hi! I'm trying to install your package and I am getting stuck on the migration. I have tried the appservice provider fix

    use Illuminate\Support\Facades\Schema;
    use Illuminate\Support\ServiceProvider;
    
    
    class AppServiceProvider extends ServiceProvider
    {
        /**
         * Register any application services.
         *
         * @return void
         */
        public function register()
        {
            //
        }
    
        /**
         * Bootstrap any application services.
         *
         * @return void
         */
        public function boot()
        {
            Schema::defaultStringLength(191);
        }
    }
    

    Ive even tried changing the database engine to innodb

    'mysql' => [
                'driver' => 'mysql',
                'url' => env('DATABASE_URL'),
                'host' => env('DB_HOST', '127.0.0.1'),
                'port' => env('DB_PORT', '3306'),
                'database' => env('DB_DATABASE', 'forge'),
                'username' => env('DB_USERNAME', 'forge'),
                'password' => env('DB_PASSWORD', ''),
                'unix_socket' => env('DB_SOCKET', ''),
                'charset' => 'utf8mb4',
                'collation' => 'utf8mb4_unicode_ci',
                'prefix' => '',
                'prefix_indexes' => true,
                'strict' => true,
                'engine' => 'InnoDB',
                'options' => extension_loaded('pdo_mysql') ? array_filter([
                    PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
                ]) : [],
            ],
    

    I was hoping maybe you might have an idea?

    opened by chrisgrim 3
  • Add an index

    Add an index

    alternate_name should have its index. Maybe with isPreferredName ? Usefull if we want to propose cities from a postcode. (Postcodes are stored in alternate_name of table geonames_alternate_names)

    opened by Nuranto 3
  • Not working on latest Laravel 5.6 version

    Not working on latest Laravel 5.6 version

    Problem 1
        - The requested package phpunit/phpunit (locked at 6.5.6, required as ~7.0) is satisfiable by phpunit/phpunit[6.5.6] but these conflict with your requirements or minimum-stability.
      Problem 2
        - Installation request for michaeldrennen/geonames ^1.0 -> satisfiable by michaeldrennen/geonames[v1.0.0].
        - michaeldrennen/geonames v1.0.0 requires ext-intl * -> the requested PHP extension intl is missing from your system.
      Problem 3
        - Installation request for sebastian/diff (locked at 2.0.1) -> satisfiable by sebastian/diff[2.0.1].
        - phpunit/phpunit 7.0.0 requires sebastian/diff ^3.0 -> satisfiable by sebastian/diff[3.0.0].
        - phpunit/phpunit 7.0.1 requires sebastian/diff ^3.0 -> satisfiable by sebastian/diff[3.0.0].
        - phpunit/phpunit 7.0.2 requires sebastian/diff ^3.0 -> satisfiable by sebastian/diff[3.0.0].
        - Conclusion: don't install sebastian/diff 3.0.0
        - Installation request for phpunit/phpunit ~7.0 -> satisfiable by phpunit/phpunit[7.0.0, 7.0.1, 7.0.2].
    
    opened by ronjunevaldoz 3
  • mmap() failed: [12] Cannot allocate memory

    mmap() failed: [12] Cannot allocate memory

    Running, "php artisan geonames:install" on a homestead installations eventually runs out of memory. PHP memory usage increases until all available memory is consumed. Not sure is this a system configuration issue or an issue with the alternate names command.

    Split file #289 of 2583 has 5000 rows. Inserting alternate names 1359/5000 [▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░░░]  27%

    mmap() failed: [12] Cannot allocate memory

    mmap() failed: [12] Cannot allocate memory PHP Fatal error:  Out of memory (allocated 4495486976) (tried to allocate 16384 bytes) in /vagrant/dr-services/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 330

    mmap() failed: [12] Cannot allocate memory

    mmap() failed: [12] Cannot allocate memory PHP Fatal error:  Out of memory (allocated 4495486976) (tried to allocate 65536 bytes) in /vagrant/dr-services/vendor/laravel/framework/src/Illuminate/Auth/SessionGuard.php on line 18

    opened by lareck 3
  • Invalid utf8 character string

    Invalid utf8 character string

    I'm getting error as following when I execute php artisan geonames:install --country=TR --country=US

    File: /home/forge/app/storage/geonames/TR.txt
    
    Combining TR.txt 10669811/10669811 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
    File: /home/forge/app/storage/geonames/US.txt
    
    Combining US.txt 302388147/302388147 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
    Num Lines: 2323203
    
    Starting to insert the records found in /home/forge/app/storage/geonames/master.txt
    We are going to try to insert 2323202 geoname records.
    Dropping the temp table named geonames_working (if it exists).
    Creating the temp table named geonames_working
    Running the LOAD DATA INFILE query...
    SQLSTATE[HY000]: General error: 1300 Invalid utf8 character string: ''Iowa,Aioua,Aiova,Ajov,Ajova,Ajovae,Ajovo,Ayova,Ayowa,Hawkeye St'
    
    opened by zek 2
  • Question - Is it possible to add countries without deleting existing ones ?

    Question - Is it possible to add countries without deleting existing ones ?

    First of all, thank you for this package that makes life easier!

    My question is in the title: Is it possible to add countries without deleting existing ones ?

    I've already installed US and Canada records
    php artisan geonames:install --country=US --country=CA
    and I'd like to add Brazil without reinstalling US and Canada ~~php artisan geonames:install --country=US --country=CA --country=BR~~ php artisan geonames:add --country=BR equivalent?

    opened by MLouis 0
  • Ignore files when exporting package

    Ignore files when exporting package

    This commit is part of a campaign to reduce the amount of data transferred to save global bandwidth and reduce the amount of CO2. See https://github.com/Codeception/Codeception/pull/5527 for more info.

    opened by simonschaufi 1
  • Foreign keys

    Foreign keys

    I was just thinking geonames could be laravel-ized and low and behold... !

    I don't need the full database of geonames. For example in a current project i need cities with their countries, administrative areas, continents etc for cities with a population over 10,000.

    Is there a reason why there is no foreign keys from geonames table to the admin tables, alternate names, hierarchy (parent and child)?

    opened by wrabit 3
Releases(v8.0.0)
Owner
Michael Drennen
Michael Drennen
Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

Introduction Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services. It handles almost all of the boilerpl

The Laravel Framework 2.2k Jan 4, 2023
Laravel Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

Introduction Laravel Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services. It handles almost all of the b

The Laravel Framework 189 Jan 5, 2023
Determine the geographical location of website visitors based on their IP addresses.

GeoIP for Laravel Determine the geographical location and currency of website visitors based on their IP addresses. GeoIP for Laravel on Packagist Geo

Daniel Stainback 1.9k Jan 6, 2023
Zarinpal is a laravel package to easily use zarinpal.com payment services in your applications

پکیج اتصال به درگاه پرداخت زرین پال zarinpal.com برای اتصال به درگاه پرداخت اینترنتی زرین پال و استفاده از api های آن می توانید از این پکیج استفاده کن

Rahmat Waisi 4 Jan 26, 2022
A package for integrating Lazerpay services with your laravel application

This is my package lazerpay-laravel This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Support

Abdulsalam Ishaq 5 Dec 22, 2022
27Laracurl Laravel wrapper package for PHP cURL class that provides OOP interface to cURL. [10/27/2015] View Details

Laracurl Laravel cURL Wrapper for Andreas Lutro's OOP cURL Class Installation To install the package, simply add the following to your Laravel install

zjango 8 Sep 9, 2018
An administrative interface package for Laravel

Laravel Administrator Project Abandoned WARNING: This project is no longer being maintained. Administrator is an administrative interface builder for

null 2k Dec 30, 2022
This package is to add a web interface for Laravel 5 and earlier Artisan.

Nice Artisan This package is to add a web interface for Laravel 5 and earlier Artisan. Installation Add Nice Artisan to your composer.json file : For

null 218 Nov 29, 2022
Laravel Soulbscription - This package provides a straightforward interface to handle subscriptions and features consumption.

About This package provides a straightforward interface to handle subscriptions and features consumption. Installation You can

Lucas Vinicius 269 Jan 1, 2023
Laravel-veneer - A suite of mocked services to use in your Laravel tests.

Laravel Veneer A suite of fixture data and methods to help make mocking 3rd party services easier. Overview Laravel Veneer aims to solve two problems

Oh See Software 4 Jun 23, 2022
Composer package which adds support for HTML5 elements using Laravels Form interface (e.g. Form::date())

Laravel HTML 5 Inputs Composer package which adds support for HTML5 elements by extending Laravel's Form interface (e.g. Form::date()) Adds support fo

Small Dog Studios 11 Oct 13, 2020
Generate services in Laravel with the artisan command

Laravel Service Generator Quickly generate services for your projects! Table of Contents Features Installation Usage Generate services Generate servic

Tim Wassenburg 15 Dec 2, 2022
Collection of Google Maps API Web Services for Laravel

Collection of Google Maps API Web Services for Laravel Provides convenient way of setting up and making requests to Maps API from Laravel application.

Alexander Pechkarev 467 Jan 5, 2023
Generate services and contracts in Laravel with the artisan command

What does it do? This package adds a new php artisan make:service {name} {--N|noContract} command. It will create a service file and its contract (int

Ludovic Guénet 18 Dec 21, 2022
Easily generate URLs to Minecraft avatars with the ability to switch between services

Minecraft Avatar URLs This library provides PHP utilities to generate URLs to Minecraft Avatars in different formats with the ability to easily change

Gigadrive UG 3 Aug 11, 2022
Create Laravel views (blade template) using 'php artisan' command-line interface

About LaraBit Have you ever wonder to create Laravel views (Blade Templates) using the same type of artisan commands that you usually use to create ne

Ragib MRB 5 Oct 15, 2021
A Laravel Artisan SQL Interactive Interface

sqli A Laravel 4 & 5 Artisan SQL Interactive Interface, plus a handful of Artisan commands to execute SQL queries. sqli It's like tinker for SQL, just

Antonio Carlos Ribeiro 61 Apr 18, 2022
Auto-generated Interface and Repository file via Repository pattern in Laravel

Auto-generated Repository Pattern in Laravel A repository is a separation between a domain and a persistent layer. The repository provides a collectio

Ngo Dinh Cuong 11 Aug 15, 2022
Free and open-source Laravel admin dashboard interface built with Livewire & Alpine.js based on Bootstrap 5

Volt Dashboard Laravel Free Frontend Web App for Laravel with Livewire & Alpine.js Never start a development project from scratch again. We've partner

Themesberg 200 Jan 4, 2023