PHP code example of hibit-dev / geodetect

1. Go to this page and download the library: Download hibit-dev/geodetect 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/ */

    

hibit-dev / geodetect example snippets


use Hibit\GeoDetect;

$geoDetect = new GeoDetect();

$country = $geoDetect->getCountry('XXX.XXX.XXX.XXX');

$country->getGeonameId();
$country->getIsoCode();
$country->getName();
$country->isInEuropeanUnion();

$country = $geoDetect->setCountriesDatabase('location_to_db_file')
                     ->getCountry('XXX.XXX.XXX.XXX');

<img alt="Country: FR" src="{{Hibit\GeoDetect::getFlagByIsoCode('FR')}}">

Hibit\GeoDetect::getFlagByIsoCode('FR', Hibit\Flag\Format::SVG) // SVG format
Hibit\GeoDetect::getFlagByIsoCode('FR', Hibit\Flag\Format::H20) // Height: 20px Width: ~30px
Hibit\GeoDetect::getFlagByIsoCode('FR', Hibit\Flag\Format::H24) // Height: 24px Width: ~36px
Hibit\GeoDetect::getFlagByIsoCode('FR', Hibit\Flag\Format::W20) // Width: 20px Height: ~13px
Hibit\GeoDetect::getFlagByIsoCode('FR', Hibit\Flag\Format::W40) // Width: 40px Height: ~26px

Route::get('/get-country', function (Illuminate\Http\Request $request) {
    $geoDetect = new Hibit\GeoDetect();

    $country = $geoDetect->getCountry($request->getClientIp());

    return response()->json([
        'geonameId' => $country->getGeonameId(),
        'isoCode' => $country->getIsoCode(),
        'name' => $country->getName(),
        'isInEuropeanUnion' => $country->isInEuropeanUnion(),
    ]);
});

@lang('geodetect.ES') //Output: Spain

__('geodetect.ES') //Output: Spain
bash
php artisan vendor:publish --tag=hibit-geodetect