PHP code example of webchefz / geo-location-calculator

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

    

webchefz / geo-location-calculator example snippets




// Import the GeoLocationCalculator class from the Webchefz\GeoLocationCalculator namespace
use Webchefz\GeoLocationCalculator\GeoLocationCalculator;

// Load Composer's autoloader to autoload the ordinates for the second location (Melbourne, Australia)
$latitudeMelbourne = -37.8136;    // Latitude of Melbourne
$longitudeMelbourne = 144.9631;   // Longitude of Melbourne

// Calculate the distance between Sydney and Melbourne using the GeoLocationCalculator class
// The GeoLocationCalculator::calculateDistance method returns the distance in kilometers
$distanceBetweenSydneyAndMelbourne = GeoLocationCalculator::calculateDistance($latitudeSydney, $longitudeSydney, $latitudeMelbourne, $longitudeMelbourne);

// Output the calculated distance in Killometers
echo $distanceBetweenSydneyAndMelbourne;




// Import the GeoLocationCalculator class from the Webchefz\GeoLocationCalculator namespace
use Webchefz\GeoLocationCalculator\GeoLocationCalculator;

// Load Composer's autoloader to autoload the les"
];

// Define details for the second city, Melbourne, in an associative array
$melbourneDetails = [
    "name" => "Melbourne",
    "country" => "Australia",
    "state" => "Victoria"
];

// Calculate the distance between Sydney and Melbourne using a GeoLocationCalculator class
$distanceBetweenSydneyAndMelbourne = GeoLocationCalculator::calculateDistanceBetweenDefinedCities($sydneyDetails, $melbourneDetails);

// Display the calculated distance between Sydney and Melbourne
echo $distanceBetweenSydneyAndMelbourne;




// Import the GeoLocationCalculator class from the Webchefz\GeoLocationCalculator namespace
use Webchefz\GeoLocationCalculator\GeoLocationCalculator;

// Load Composer's autoloader to autoload the he same GeoLocationCalculator class
$distanceBetweenSwitchedCities = GeoLocationCalculator::calculateDistanceBetweenDefinedCities($switchedCity1, $switchedCity2);

// Display the recalculated distance between the switched cities
echo $distanceBetweenSwitchedCities;