PHP code example of cslash / laravel-geoname

1. Go to this page and download the library: Download cslash/laravel-geoname library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cslash / laravel-geoname example snippets


use Cslash\GeoName\Facades\GeoName;

$label = GeoName::fromRequest(); 
// Returns something like "FR-NORTH" or "US-WEST"

use Cslash\GeoName\Facades\GeoName;

$label = GeoName::fromIp('8.8.8.8');

use Cslash\GeoName\Data\GeoContext;
use Cslash\GeoName\Facades\GeoName;

$context = new GeoContext(
    countryCode: 'FR',
    regionName: 'Brittany',
    regionCode: 'BRE',
    latitude: 48.1173,
    longitude: -1.6778
);

$label = GeoName::fromContext($context); // "FR-WEST"

return [
    'fallback' => 'XX-UNKNOWN', // Returned when IP location cannot be determined
    'unknown_zone' => 'UNKNOWN', // Returned when coordinates are missing for generic resolution

    'countries' => [
        'FR' => [
            'thresholds' => [47.5, 44.5, -0.5, 4.5], // north, south, west, east
            'region_map' => [
                'BRE' => 'WEST',
                'NOR' => 'WEST',
                // ...
            ],
        ],
    ],
];
bash
php artisan vendor:publish --tag="geoname-config"