PHP code example of frostybee / geobee

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

    

frostybee / geobee example snippets




use Frostybee\Geobee\Calculator;

/*
 * Calculate the distance from downtown Montreal to Laval.
 * From: Ville-Marie 
 *       postal code area: H3A
 *       Latitude/Longitude: 45.4987, -73.5703
 * To: Laval 
 *     postal code area: H7T 
 *     Latitude/Longitude: 45.55690, -73.7480
 */
$calculator = new Calculator();
$distance = $calculator->calculate(
    $from_latitude,
    $from_longitude,
    $to_latitude,
    $to_longitude
)->getDistance(); // Distance in meters.

$distance = $calculator->to('mi', 3, false);

// $calculator->toMany(array, $decimals, $round);
$results = $calculator->toMany(['km', 'mi'], 3, true);

array(2) {
  ["km"]=>
  float(15.298)
  ["mi"]=>
  float(9.506)
}

//$calculator->toAll($decimals, $round);
$results = $calculator->toAll(2, true);

array(6) {
  ["m"]=>
  float(15297.83)
  ["km"]=>
  float(15.3)
  ["ft"]=>
  float(50189.72)
  ["yd"]=>
  float(16729.91)
  ["mi"]=>
  float(9.51)
  ["nm"]=>
  float(8.26)
}
 php
$distance = $calculator->calculate(
    $from_latitude,
    $from_longitude,
    $to_latitude,
    $to_longitude
)->to('km'); // Get the distance in kilometers.