PHP code example of thbappy7706 / geo-details

1. Go to this page and download the library: Download thbappy7706/geo-details 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/ */

    

thbappy7706 / geo-details example snippets

bash
e GeoDetails\GeoLocationService;

// Instantiate the GeoLocationService class
$geoService = new GeoLocationService();

// Specify the IP address you want to retrieve details for
$ip = '8.8.8.8';

// Fetch and display geolocation details
$latitude = $geoService->getLatitude($ip);
$longitude = $geoService->getLongitude($ip);

if ($latitude !== null && $longitude !== null) {
    echo "Latitude: " . $latitude . ", Longitude: " . $longitude;
} else {
    echo "Error: Unable to retrieve location details.";
}

bash
$geoService = new GeoLocationService();
$ip = '8.8.8.8';

echo "Latitude: " . $geoService->getLatitude($ip) . PHP_EOL;
echo "Longitude: " . $geoService->getLongitude($ip) . PHP_EOL;
echo "Timezone: " . $geoService->getTimezone($ip) . PHP_EOL;
echo "Currency: " . $geoService->getCurrency($ip) . PHP_EOL;

bash
$latitude = $geoService->getLatitude('127.0.0.1:8000');

if ($latitude === null) {
    echo "Error: Unable to retrieve latitude.";
} else {
    echo "Latitude: " . $latitude;
}

bash
$details = $geoService->getDetails('127.0.0.1:8000');

if (isset($details['error']) && $details['error']) {
    echo "Error: " . $details['reason'];
} else {
    echo "Details retrieved successfully.";
}

bash
$ip = '8.8.8.8';

echo "Latitude: " . getLatitude($ip) . PHP_EOL;
echo "Longitude: " . getLongitude($ip) . PHP_EOL;
echo "Timezone: " . getTimezone($ip) . PHP_EOL;
echo "Currency: " . getCurrency($ip) . PHP_EOL;