PHP code example of roundly-consulting / geolocation-for-laravel
1. Go to this page and download the library: Download roundly-consulting/geolocation-for-laravel 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/ */
roundly-consulting / geolocation-for-laravel example snippets
use RoundlyConsulting\Geolocation\DataTransferObjects\Coordinates;
use RoundlyConsulting\Geolocation\Enum\DistanceType;
use RoundlyConsulting\Geolocation\Facades\Geolocation;
$location = Geolocation::locateRequest(); // the client's IP; null when nothing resolves
$location?->city; // "Mountain View"
$location?->countryIsoCode; // "US"
$location?->timezone; // "America/Los_Angeles"
$office = Geolocation::locateAddress('1600 Amphitheatre Pkwy, Mountain View');
$office?->coordinates(); // Coordinates(37.4224, -122.0841)
$distance = Geolocation::distanceBetween(
new Coordinates(48.1482, 17.1067),
new Coordinates(49.2000, 16.6068),
DistanceType::Driving,
);
$distance?->humanReadableDistance; // "133 km"
$distance?->durationInSeconds; // 5400